C# Convert.ToInt32 Method



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
Updated on: 2020-06-23T07:49:14+05:30

747 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements