创建一个字符串数组并将索引和值显示给控制台

时间:2012-12-09 20:57:56

标签: c#

这是我到目前为止的代码:

string[] animals = { "cow", "pig", "dog", "cat", "mouse", "giraffe", "moose", "deer", "lion", "hippo" };
Console.WriteLine("{0,5}{1,8}", "animal", "index");
Console.ReadLine();

1 个答案:

答案 0 :(得分:5)

for(int i = 0; i < animals.length();i++) //Go through the whole array
{
     Console.WriteLine(animals[i] + " " + i); //Output the animal and the index
}
Console.ReadLine();  //Wait for user input.