Best way to handle Integer overflow in C#?

前端 未结 6 440
臣服心动
臣服心动 2020-11-28 07:46

Handling integer overflow is a common task, but what\'s the best way to handle it in C#? Is there some syntactic sugar to make it simpler than with other languages? Or is th

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 07:48

    Old thread, but I just ran into this. I didn't want to use exceptions. What I ended up with was:

    long a = (long)b * (long)c;
    if(a>int.MaxValue || a

提交回复
热议问题