illustrates how to use arrays 2 : Array : Collections Data Structure C# Source Code


Custom Search

C# Source Code » Collections Data Structure » Array »

 

illustrates how to use arrays 2









    

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/


/*
  Example10_1.cs illustrates how to use arrays
*/

using System;

public class Example10_1
{

  public static void Main()
  {

    // int arrays
    int[] intArray = new int[10];
    int arrayLength = intArray.Length;
    Console.WriteLine("arrayLength = " + arrayLength);
    for (int counter = 0; counter < arrayLength; counter++)
    {
      intArray[counter] = counter;
      Console.WriteLine("intArray[" + counter + "] = " +
        intArray[counter]);
    }

    // char arrays
    char[] charArray = new char[5];
    Console.WriteLine("charArray[0] = " + charArray[0]);
    charArray[0] = 'h';
    charArray[1] = 'e';
    charArray[2] = 'l';
    charArray[3] = 'l';
    charArray[4] = 'o';
    for (int counter = 0; counter < charArray.Length; counter++)
    {
      Console.WriteLine("charArray[" + counter + "] = " +
        charArray[counter]);
    }

    // string arrays
    string[] stringArray = new string[2];
    Console.WriteLine("stringArray[0] = " + stringArray[0]);
    stringArray[0] = "Hello";
    stringArray[1] = "World";
    foreach (string myString in stringArray)
    {
      Console.WriteLine("myString = " + myString);
    }

  }

}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Collections Data Structure
» Array