How to convert a string into 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: 22-Jun-2020

204 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements