CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Posts
    1

    Question String to integer

    Hi every body!
    Could someone help me in converting a string to integer in C#?
    Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    18
    You can use the System.Convert class.

    Like this:
    int iNumber = System.Convert.ToInt32(myString);

  3. #3
    Join Date
    May 2002
    Posts
    6

    Cool

    Easy way of converting a string to an interger
    int i = Int32.Parse(String);

    Similarly converting a string to a long is done as
    long d = Int64.Parse(String);

  4. #4
    Join Date
    May 2002
    Location
    Netherlands
    Posts
    4

    Also works..

    Similar to what armtusk replied, the following also works (just a matter of taste, I think using the same datatypes adds to more consistant code):

    int i = int.Parse(String);

    or

    long d = long.Parse(String);

    Of course, it also works with doubles and floats .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured