illustrates how to initialize arrays
/*
Example10_3.cs illustrates how to initialize arrays
*/
using System;
public class Example10_3 {
public static void Main() {
// int arrays
int[] intArray = new int[5] {10, 20, 30, 40, 50};
for (int counter = 0; counter < intArray.Length; counter++)
{
Console.WriteLine("intArray[" + counter + "] = " +
intArray[counter]);
}
// char arrays
char[] charArray = new char[] {'h', 'e', 'l', 'l', 'o'};
for (int counter = 0; counter < charArray.Length; counter++)
{
Console.WriteLine("charArray[" + counter + "] = " +
charArray[counter]);
}
// string arrays
string[] stringArray = {"Hello", "World"};
foreach (string myString in stringArray)
{
Console.WriteLine("myString = " + myString);
}
}
}
Related examples in the same category