View Single Post
  #5 (permalink)  
Old March 3rd, 2010, 10:27 AM
DrPurdum DrPurdum is offline
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Indexing

PeterPeiGuo's code is correct and simplier. However, in my own defense, the purpose of the exercise was to get people to think about array indexing, Indeed, the exercise specifically asks for array indexing. That's why I framed it as a "pure" array rather than an array object, which Peter does.

Another thing to keep in mind: Microsoft provides language features in C# that are not always found in other languages (e.g., LINQ) and, if you end up programming professionally, you may find a certain language feature missing in your new development language. Java, for example, has a huge following and Microsoft has added some nifty features to C# to entice people away from Java to C#. That's one reason I tend to concentrate on the "core" language features in my books, rather than the odd features. True, I do cover most of these cool features, but I rarely use them in my consulting code. Why? Because oft times I have to port that code to another environment and language where that feature isn't available. About the only time I use an unusual language feature is when I can see that it offers a significant improvement in performance.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)