Wednesday, June 23, 2004

foreach statement

using <class> is like with <an object> in Pascal. And I think there is a situation where such a feature will be useful.

The foreach statement always involves declaration of a local variable:

foreach( XmlElement element
in doc.SelectNodes(xpath) )
{
Console.WriteLine( "{0} of type {1}",
element.Name,
element.GetAttribute("Type"));
}

How often You name the variable with i? While there is always the variable in the foreach statement it's possible simply omit its name:

foreach( XmlElement in doc.SelectNodes(xpath) )
{
Console.WriteLine( "{0} of type {1}",
Name, GetAttribute("Type") );
}


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?