How do I convert uint to int in C#?

前端 未结 8 1484
时光说笑
时光说笑 2020-12-05 03:54

How do I convert uint to int in C#?

相关标签:
8条回答
  • 2020-12-05 04:22

    Take note of the checked and unchecked keywords.

    It matters if you want the result truncated to the int or an exception raised if the result doesnt fit in signed 32 bits. The default is unchecked.

    0 讨论(0)
  • 2020-12-05 04:31
    int intNumber = (int)uintNumber;
    

    Depending on what kind of values you are expecting, you may want to check how big uintNumber is before doing the conversion. An int has a max value of about .5 of a uint.

    0 讨论(0)
提交回复
热议问题