Create a new project in Visual Studio using C# Console Project. Declare an array of strings with the size of 12. Insert 12 different strings into the array. In a foreach loop display the contents of the array to the console.
using System;
class Array
{
static void Main()
{
//string array declaration
string[] str = new string[12] {"hi", "hello", "how", "are", "you",
"ok", "bye", "done", "yes", "no", "bye", "ok"};
//integer variable declaration and initialization
int k=0;
//display the array content on the computer screen
foreach (string i in str)
{
Console.WriteLine("str[{0}] = {1}", k, i);
k = k + 1;
}
}
}
OUTPUT:
str[0] = hi
str[1] = hello
str[2] = how
str[3] = are
str[4] = you
str[5] = ok
str[6] = bye
str[7] = done
str[8] = yes
str[9] = no
str[10] = bye
str[11] = ok
Get Answers For Free
Most questions answered within 1 hours.