C# 字符串列表中的随机字符串

C# 字符串列表中的随机字符串,c#,random,C#,Random,我想从字符串列表中生成一个字符串。我这样做了,但它只显示了阵列的数量: Random r1 = new Random(); string[] fruits = new string[7]; fruits[0] = "cherry"; fruits[1] = "blueberry"; fruits[2] = "banana"; fruits[3] = "melon"; fruits[4] = "apple"; fruits[5] = "pear"; fruits[6] = "watermelon"

我想从字符串列表中生成一个字符串。我这样做了,但它只显示了阵列的数量:

Random r1 = new Random();
string[] fruits = new string[7];
fruits[0] = "cherry";
fruits[1] = "blueberry";
fruits[2] = "banana";
fruits[3] = "melon";
fruits[4] = "apple";
fruits[5] = "pear";
fruits[6] = "watermelon";

Console.WriteLine(r1.Next(fruits.Length));
例如,水果[2]是数组中的第三个,因为它从0开始

    Console.WriteLine(fruits[r1.Next(fruits.Length)]);