- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I identify if a string is a number in C#?
Let us say our string is −
string str = "3456";
Now, to check whether the entered string is a number or not −
str.All(c => char.IsDigit(c))
The above returns true if the string is a number, else false.
Here is the complete code −
Example
using System; using System.Linq; namespace Demo { public class MyApplication { public static void Main(string[] args) { string str = "3456"; // checking if string is a number or not Console.WriteLine(str.All(c => char.IsDigit(c))); } } }
Output
True
- Related Articles
- How do I convert a string to a number in Python?
- How do I convert a number to a string in Python?
- How do I determine if a String contains another String in Java?
- How do I convert a double into a string in C++?
- How do we find out if first character of a string is a number in java?
- How do I check if a string has alphabets or numbers in Python?
- Check if a given string is a valid number in C++
- How do I do a case insensitive string comparison in Python?
- How do I define string constants in C++?
- How do I create a random alpha-numeric string using C++?
- How do I wrap a string in a file in Python?
- How do I modify a string in place in Python?
- How do I convert a Swift array to a string?
- How do I convert a float number to a whole number in JavaScript?
- How do I format a string using a dictionary in Python 3?

Advertisements