Arrays, Collections & String Manipulation |
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#: |
• Rectangular array (one in which each row contains an equal number of columns) |
• 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).
REFERENCES:C# School book - |
programmersheaven
0 comment:
إرسال تعليق