I found an example for casting. When I try to cast long to int, I get the following output.
long e = 10;
int x = (int) e ;
WriteLine($"e is {e:N0} and x is {x:N0} ");
e = long.MaxValue;
x = (int) e;
WriteLine($"e is {e:N0} and x is {x:N0} ");
e = 5_000_000_000;
x = (int) e;
WriteLine($"e is {e:N0} and x is {x:N0} ");
For case 1, 10 can fit into int, so there is no issue,
For case 2, value -> long max value won't fit in int, so the output is 1
For case 3, value = 5_000_000_000, which also won't fit in int, so it should output 1, but it outputs 705,032,704 Can anyone explain why we are getting this value?
Output of above code is :
e is 10 and x is 10
e is 9,223,372,036,854,775,807 and x is -1
e is 5,000,000,000 and x is 705,032,704