整数类型转换 Convert long to int

阳光穿透心脏的1/2处 2022-12-31 05:17 202阅读 0赞

https://stackoverflow.com/questions/5192862/how-to-convert-long-to-int-in-net

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

整型存储最大不能超过15位。

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

可以用TryParse() 把一个输入的 string 字符串转换得到一个 long 长整型。

  1. String Am = AmountTextBox.Text.ToString();
  2. long l;
  3. 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.

如果转换失败,则会返回false, 因此使用这个方法很案例。

Otherwise, converting a long to int is a easy as

或者 把一个 长整型转换成整型也很简单:直接在 前面 加 (int)

  1. int i = (int)yourLongValue;

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

发表评论

表情:
评论列表 (有 0 条评论,202人围观)

还没有评论,来说两句吧...

相关阅读