long[] b = new long[1];
int i1 = b[0]; // compile error as it should
// no warning at all, large values gets converted to negative values silently
foreach (int i2 in b)
{
}
class Customer : Person{}
Person[]p = new Person[]{mypers};
// no warning at all, throws typecastexception at runtime
foreach (Customer c in p)
{
}
I know they cannot simply fix it, because it would break existing programs.
But why don't they make a compatibility option in c# compiler where I can turn on typesafe foreach block generation at least for new programs or programs where I am sure it works?