1
我们能在C#使用检查检查溢出为比特的特定数目,如说25,30等检查关键字用于检查在c#指定的位数
int A = 0;
int B = 1000;
checked
{
A += 1000000;
B = B * A;
}
例如,在上述例如,A可以检查27位溢出。
我们能在C#使用检查检查溢出为比特的特定数目,如说25,30等检查关键字用于检查在c#指定的位数
int A = 0;
int B = 1000;
checked
{
A += 1000000;
B = B * A;
}
例如,在上述例如,A可以检查27位溢出。
不,没有像C#支持的东西。
你也许能来是写自己的方法,该方法用于检查“正常”类型的溢出(为int
32位,64 long
等),然后也强加于有效一些额外的限制,最近值。理想情况下,我建议为此创建自己的包装类型,例如
public struct Int25
{
private readonly int value;
// Constructor etc, and operators which always make sure the result
// is within the appropriate range
}
请提供一些关于您的问题的信息。你的问题似乎是比原来的问题更多的解决方案。 – PVitt 2011-04-28 08:42:27