 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
Advertisements
 