I have the following 2 blocks of code that are designed to indicate the type assigned to the compiler with the var keyword.
var b = 0x80000000 - 0x1; Console.WriteLine("b: {0}", b); Console.WriteLine("b.GetType()={0}", b.GetType()); uint val1 = 0x80000000; int val2 = 0x1; var c = val1 - val2; Console.WriteLine("c: {0}", c); Console.WriteLine("c.GetType(): {0}", c.GetType());
Conclusion:
b: 2147483647 //Result of UInt32-Int32 //(as compiler assigns datatype in the //order of int, uint, long and ulong) b.GetType()=System.UInt32 //OK c: 2147483647 //Uint32-Int32 c.GetType(): System.Int64 //Not Understood, why not UInt32 ?
If var b and var c have almost the same initialization where var c is even, then why does it give an unexpected System.Int64 data type?
source share