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

Posted on 2006-05-03
Medium Priority
Last Modified: 2008-01-09

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,
Question by:tmitchell68
LVL 10

Accepted Solution

rivusglobal earned 800 total points
ID: 16601573
       string s = "98";
        int i = Int32.Parse(s);
        int x = i + 2;
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 400 total points
ID: 16601625
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.

Assisted Solution

seazium earned 400 total points
ID: 16601634
Number = Int32.Parse(Text);


Assisted Solution

nguyenvinhtu earned 400 total points
ID: 16601843
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question