The problem here is that it foreachwas developed before the generic, which did not exist before .NET 2.0. Since .NET 1.1, if you used a collection class, the IEnumeratorinterface property Currentalways returns System.Object.
Having a foreach throw, you can write:
foreach(string item in collection)
Instead of explicitly writing:
foreach(object temp in collection)
{
string item = (string)temp;
Of course, with .NET 2 this is no longer a problem.
source
share