How to convert long to int in .net?

后端 未结 7 2452
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 15:19

I am developing window phone 7 application in silverlight. I am new to the window phone 7 application. I have the long value in String format as follows

String A         


        
7条回答
  •  迷失自我
    2021-02-18 16:07

    You can't store a 15 digit integer since the maximum value for an integer is 2,147,483,647.

    What's wrong with a long-Value?

    You could use TryParse() to get the long-Value from yout user input:

    String Am = AmountTextBox.Text.ToString();
    long l;
    Int64.TryParse(Am, out l);
    

    It will return false if the text can't be converted to long, so it's pretty safe to use.

    Otherwise, converting a long to int is a easy as

    int i = (int)yourLongValue;
    

    if you're happy with discarding MSBs and taking LSBs.

提交回复
热议问题