*/
Stuck? Need help? Ask questions on our forums.

Other Views

corner
*/

C# School - Arrays, Collections, and String Manipulation - Lesson #8 - Page 1

                     Next Page



Arrays, collections and string Manipulation

If you are new to C# School
This is the 8th in the series of lessons of our C# School. The C# School is a kind of interactive learning platform where those who want to learn .NET with C# can find help and support. With one issue a week, describing some areas of the C# Programming Language with the Microsoft .Net Platform, this is not the same traditional passive tutorial where the author only writes and the reader only reads. There will be exercise problems at the end of each issue, which the reader is expected to solve after reading the issue. The solution to these problems will be provided in the next issue for testing purposes. There is also a dedicated message board attached with the school, where you can ask questions about the article, and the author will respond to your question within 2/3 days. You can send your suggestions, feedback or ideas on how these lessons can be improved to either the Author ( farazrasheed@acm.org)or the WEBMASTER ( info@programmersheaven.com).

For previous lessons: Lesson Plan Today we will explore arrays, collections and string manipulation in C#. First of all, we will explore multidimensional rectangular and jagged arrays. We will also explore how foreach iterates through a collection. Then we will move to collections and see how they are implemented in C#. Later, we will explore different collections like ArrayLists, Stacks, Queues and Dictionaries. Finally, we will see how strings are manipulated in C#. We will explore both the string and the StringBuilder types.

Arrays Revisited As we have seen earlier, an array is a sequential collection of elements of a similar data type. In C#, an array is an object and thus a reference type, and therefore they are stored on the heap. We have only covered single dimension arrays in the previous lessons, now we will explore multidimensional arrays.

Multidimensional Arrays A multidimensional array is an 'array of arrays'. A multidimensional array is the one in which each element of the array is an array itself. It is similar to tables in a database where each primary element (row) is a collection of secondary elements (columns). If the secondary elements do not contain a collection of other elements, it is called a 2-dimensional array (the most common type of multidimensional array), otherwise it is called an n-dimensional array where n is the depth of the chain of arrays. There are two types of multidimensional arrays in C#: 1. Rectangular array (one in which each row contains an equal number of columns) 2. Jagged array (one in which each row does not necessarily contain an equal number of columns)

The images below show what the different kinds of arrays look like. The figure also shows the indexes of different elements of the arrays. Remember, the first element of an array is always zero (0).

http://www.programmersheaven.com/articles/faraz/lesson8_img1ver2.gif



                     Next Page



corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.