Today I started the chapter on Collections and Generics, which is bound to be a very interresting chapter for these are the things a developer comes into contact every day.
The first lesson covered the basics about collections. Adding and Removing items was a breeze, not much new there.
I learned that there are 3 different ways to iterate through a collection:
- using the numeric indexer: coll(1)
- using the foreach statement: foreach item as string in coll
- using the GetNumerator method
This last one was new to me. I never used this before. This method returns a IEnumerator object that allowed you to move through the items of the collection, forward only, using the MoveNext and Current methods. Very cool, but redundant because the foreach language construct does exactly the same, and is much easier to implement.
Sorting items of a collection is both very easy and exiting. The default implementation of Sort uses a Comparer class, but an overloaded construct of Sort also allows you to specify another comparer class, even your own custom class, as long as it implement the IComparer interface.
Cool stuff.... ;-)
The lab was easy and I got all the review questions right. :D
Next lesson I'll be working with Sequential Lists. Can't wait ;-)
Cheers
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment