Optimal use of foreach
Mont Rothstein <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <[email protected]> |
When using foreach if the collection is a property will it be called on each
pass or only once?
Can I do:
foreach (string key in myDictionary.Keys)
{
}
or will that call Keys each time, therefore requiring that I do:
Dictionary<string, string>.KeysCollections keys;
keys = myDictionary.Keys;
foreach (string key in keys)
{
}
Thanks,
-Mont
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives