Wednesday, February 1, 2012

Wednesday, 2-1-12

static void Main(string[] args)
{
SystemArrayFunctionality();
}

static void SystemArrayFunctionality()
{
Console.WriteLine("=> Working with System.Array");
//initialize items at startup
string[] gothicBands = { "Tones on Tail", "Bauhaus", "Sisters of Mercy" };

//print out names in declared order
Console.WriteLine("-> Here is the array:");
for (int i = 0; i < gothicBands.Length; i++)
{
//print a name
Console.Write(gothicBands[i] + ", ");
}
Console.WriteLine("\n");

//reverse them
Array.Reverse(gothicBands);
Console.WriteLine("-> The reversed array");
//...and print them
for (int i = 0; i < gothicBands.Length; i++)
{
//print a name
Console.Write(gothicBands[i] + ", ");
}
Console.WriteLine("\n");

//clear out all but the final member
Console.WriteLine("-> Cleared out all but one...");
Array.Clear(gothicBands, 1, 2);
for (int i = 0; i < gothicBands.Length; i++)
{
//print a name
Console.Write(gothicBands[i] + ", ");
}
Console.WriteLine();
}

No comments:

Post a Comment