Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Sai Subramanyam

Convert a string representation of number to an integer, using the int.Parse method in C#. If the string cannot be converted, then the int.Parse method returns an exception

Let’s say you have a string representation of a number.

string myStr = "200";

Now to convert it to an integer, use the int.Parse(). It will get converted.

int.Parse(myStr);

Example

Live Demo

using System.IO;
using System;
class Program {
   static void Main() {
      int res;
      string myStr = "200";
      res = int.Parse(myStr);
      Console.WriteLine("String is a numeric representation: "+res);
   }
}

Output

String is a numeric representation: 200

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.