Convert String to Int in C#



Let’s say our string is −

string str ="9999";

Now, use the Int32.Parse() to convert the string into integer −

int n = Int32.Parse(str);

Now display the integer value as shown in the following code −

Example

using System;
class Demo {
   static void Main() {
      string str ="9999";
      int n = Int32.Parse(str);
      Console.WriteLine(n);
   }
}
Updated on: 2020-06-22T11:00:34+05:30

345 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements