Does anyone know if there is an atoi function in C#?

Hi,

Does anyone know if there is an atoi-type function in C# that will take a string - say "98" - and will return the corresponding integer value - 98 in this case?

If there is such a function, do you know the namespace that has to be included?

Thanks in advance,
Tim
tmitchell68Asked:
Who is Participating?
 
rivusglobalCommented:
       string s = "98";
        int i = Int32.Parse(s);
       
        int x = i + 2;
       
        MessageBox.Show(x.ToString());
0
 
Jaime OlivaresSoftware ArchitectCommented:
Also consider that Parse() function will generate an exception if string doesn't contain valid characters. So you have 2 choices:
1) To use try/catch to trap the exception
2) To use TryParse() instead of Parse() to receive a boolean value indicating if parsing was successful.
0
 
seaziumCommented:
Number = Int32.Parse(Text);

0
 
nguyenvinhtuCommented:
string strToConvert = "98";
Convert.ToInt32(strToConvert); //Belong to System.Convert class of System namespace.

so, before you can use the function, make a reference to System namespace: "using System;" on the top of your class
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.