The MSDN examples are just compile time errors.
It's just I see @JonSkeet uses it an answer here: https://stackoverflow.com/a/263416/360211 and I can't see why if it's just compile time.
static void Main()
{
const int x = 4;
int y = int.MaxValue;
int z = x*y;
Console.WriteLine(z);
Console.ReadLine();
}
Produces -4
, same as this:
static void Main()
{
unchecked
{
const int x = 4;
const int y = int.MaxValue;
int z = x*y; // without unchecked, this is compile error
Console.WriteLine(z);
Console.ReadLine();
}
}
This throws runtime:
static void Main()
{
checked
{
const int x = 4;
int y = int.MaxValue;
int z = x*y; //run time error, can checked be set system wide?
Console.WriteLine(z);
Console.ReadLine();
}
}
So is Jon doing this because it could be set system wide, compiler flag or otherwise?