C# Convert.ToInt32 Method

CsharpProgrammingServer Side Programming

Use Convert.ToInt32 method to convert text to an integer.

Firstly, set a string.

string str = "12";

Now, use the Convert.ToInt32() method the above string to number.

Convert.ToInt32(str);

Let us see the complete example.

Example

 Live Demo

using System;
class Program {
   static void Main() {
      string str = "12";
      Console.WriteLine("String: "+str);
      int n = Convert.ToInt32(str);
      Console.WriteLine("Number: "+n);
   }
}

Output

String: 12
Number: 12
raja
Published on 12-Sep-2018 13:11:09
Advertisements