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