var, , -:
var x = -1U;
-1 , uint - long
Console.WriteLine(x.GetType().Name);
Console.WriteLine(x);
As said, you can use the keyword uncheckedso that the compilation knows that it should not perform an overflow check. Quote from MSDN :
Invalid keyword used to suppress overflow for integral types of arithmetic operations and transforms.
So, this should compile and run, and x will be of type ulong:
var x = unchecked((ulong)-1);
source
share