Windows Phone Developers

Wednesday, October 22, 2008

Convert String to Long using C#

Int64..::.Parse Method converts the string representation of a number to its 64-bit signed integer equivalent. This can be used to convert the string to long as shown below

public long Convert2Long(String Str1)

{

try

{

long LngString = Int64.Parse(Str1);

return LngString;

}

catch (System.FormatException)

{

Console.WriteLine("Parameter is not in required format");

return -1;

}

}


Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

7 comments:

  1. Hi;

    Your functions is only convert integer no. if i write
    1.20 it return -1
    or 0.02 it return -1

    thanks.

    ReplyDelete
  2. Hi,
    Your function can only convert integers,

    i tried to convert 1.2 an 0.02, both gave me result -1.

    ReplyDelete
  3. What do you two think, what a function wich converts to Long is doing? converting floats an doubles?

    ReplyDelete
  4. Int64 is a 64-bit Integer or Long. If you want to convert a double, you need to use Double.Parse().

    ReplyDelete