How to convert a string to int in C# – Programming Code Examples
C# C# Console Application

How to convert a string to int in C#1 min read

Convert.ToInt32() Method – Convert string to numeric value

.net Convert class allow us to convert a base data type to another base data type. Convert class ToInt32(String) method converts the specified string representation of a number to an equivalent 32 bit signed integer.

Convert.ToInt32(String) overloaded method require to pass a parameter. this parameter name is ‘value’ which data type is System.String. this parameter pass the string that contains the number to convert. this method return a 32 bit signed integer that is equivalent to the number in value. if the parameter value is null then the method return zero (0).

we also can convert a string object to numeric value (int 32 bit integer) by using Int32.Parse(String) method or Int32.TryParse method. Int32.TryParse method returns an additional value that indicate whether the conversion succeed.

The following console c# example code demonstrate us how can we convert a string to int32 numeric value in .net framework.

C# Code:


Leave a Comment