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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.