« SelectNodes requires XmlNamespaceManager when XML Schema file has a default namespace attribute. | Main | Getting started with DataAdapters, DataSets, DagaGrids »

Working with collections

“foreach (Foo f in bar)” will do a dynamic cast to type Foo from the type returned by the IEnumerator for bar. No compile time warning is generated if bar returns a type that might be cast to Foo, i.e. if it’s a collection of Objects.

If there’s no possibility of casting to Foo, a compile time error occurs.

With a try block around the foreach, code execution in the debugger jumps ahead to an unexpected position which the try block instead of directly to the finally block. This appears to be a bug…

 

There are tools available for generating strongly typed collections.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)