Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# how to check string is number

string s1 = "123";
string s2 = "abc";

bool isNumber = int.TryParse(s1, out int n); // returns true
isNumber = int.TryParse(s2, out int n); // returns false
Comment

c# see if string is int

bool result = int.TryParse("123", out var n);
Comment

C# checking if a value is a int


using System;

namespace Help
{
    class Program
    {
        static void Main(string[] args)
        {
            string text1 = "Hello";
            string text2 = "29";

            if (CheckInt(text1) == true) // if text 1 is a int, it's going to print : Text 1 is a int
            {
                Console.WriteLine("Text 1 is a int");
            }
            else if (CheckInt(text2) == true) // if text 2 is a int, which is the case, it's going to print : Text 2 is a int
            {
                Console.WriteLine("Text 2 is a int");
            }
        }
        public static bool CheckInt(string input)
        {
            int number = 0;
            return int.TryParse(input, out number);
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: raq query ef core 
Csharp :: c# unit test exception using try catch 
Csharp :: caesar cipher in C# 
Csharp :: w3develops 
Csharp :: how to use monitor from system.threading in c# 
Csharp :: Get a list of distinct values in List 
Csharp :: textbox gotfocus wpf 
Csharp :: net user add ne user windows 10 
Csharp :: if statement in razor using "?" and ":" 
Csharp :: How to get selected item from Dropdown in GridView 
Csharp :: dctionary literal c# 
Csharp :: run in wpf 
Csharp :: c# insert backslash in string 
Csharp :: unity how to check index of enum 
Csharp :: c# convert bool to string 
Csharp :: c# Write a program to reverse an array or string 
Csharp :: c# convert bitmap to image 
Csharp :: c# switch example 
Csharp :: Default property value in C# 
Csharp :: array to object c# 
Csharp :: string.format() c# 
Csharp :: bezier_curve 
Csharp :: cloudmailin c# 
Csharp :: set time on audio source unity 
Csharp :: Read csv file into wpf C# 
Csharp :: SceneManagment by BuildIndex 
Csharp :: dsharp emoji from string 
Csharp :: pcamera 
Csharp :: unity time.fixeddeltatime 
Csharp :: how to fill dictionary in c# 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =