Can I convert long to int?
Just do (int)myLongValue
. It'll do exactly what you want (discarding MSBs and taking LSBs) in unchecked
context (which is the compiler default). It'll throw OverflowException
in checked
context if the value doesn't fit in an int
:
int myIntValue = unchecked((int)myLongValue);
Convert.ToInt32(myValue);
Though I don't know what it will do when it's greater than int.MaxValue.