C-sharp Advanced programming
Chapter 7 there is such a code in budget characters and forced type conversions
checked
{
Currency balance = (Currency)(-50.50);
}
where Currency is a custom class that overrides cast
public static explicit operator Currency (float value)
{
uint dollars = (uint)value;
ushort cents = (ushort)((value - dollars) * 100);
return new Currency(dollars, cents);
}
adding checked to the code inside the method body alone can trigger an exception assigned to uint with a negative number, but not if the overridden method is called through the class"s cast as above. The book says
The actual location of theoverflow exception is not at all in the Main () routine-- it occurs in the code of the cast operator, which is called in the Main () method and is not marked as checked
what does this mean? Please advise