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

Posted on 2006-05-03
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

           string s = "98";
            int i = Int32.Parse(s);
            int x = i + 2;
    LVL 55

    Assisted Solution

    by:Jaime Olivares
    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.
    LVL 3

    Assisted Solution

    Number = Int32.Parse(Text);

    LVL 4

    Assisted Solution

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now