Hi,
In .NET Framework, there are some classes which use SomethingCollection
syntax.
For example, when dealing with SqlCommand
, it has a parameter Parameters
of type SqlParameterCollection
. Since it does not have a form of IEnumerable<SqlParameter>
(or IList<SqlParameter>
or something similar), it is impossible to write:
foreach (var c in sqlCommand.Parameters)
{
Debug.WriteLine(string.Concat(c.ParameterName, ": ", c.Value));
}
Instead, var
must be replaced by an explicit SqlParameter
.
The thing is very similar when dealing with Windows Forms controls (collections of listview items, etc.), and exists in other classes.
What is this thing? Why such classes exist and are used instead of generic IEnumerable
s/IList
s?