I have a collection of nullable ints.
Why does compiler allows to iteration variable be of type int not int? ?
List<int?> nullableInts = new List<int?>{1,2,3,null};
List<int> normalInts = new List<int>();
//Runtime exception when encounter null value
//Why not compilation exception?
foreach (int i in nullableInts)
{
//do sth
}
Of course I should pay attention to what I iterate through but it would be nice if compiler reprimanded me:) Like here:
foreach (bool i in collection)
{
// do sth
}
//Error 1 Cannot convert type 'int' to 'bool'