-8
 class Palette
 {  
      public static void Main()
      {    
           int array = new int [5];
           if (array[] = 0)
           {
                   Console.WriteLine("It's blue");
           }
           if (array[] = 1)
           {
                   Console.WriteLine("It's Violet");
           }
           if (array[] = 2)
           {
                   Console.WriteLine("It's red");
           }
           if (array[] = 3)
           {
                   Console.WriteLine("It's Black");
           }
           if (array[] = 4)
           {
                   Console.WriteLine("It's green");
           }
           Random ran = new Random();
           int r = ran.Next(array.Length);
           string Token = (array[r]);
           Console.WriteLine(Token);
   }
}

这是行不通的。我怎样才能让它工作。

4

2 回答 2

3

你在寻找这样的东西吗?

public static void Main()
{
    string[] array = new string[5];
    array[0] = "It's blue";
    array[1] = "It's Violet";
    array[2] = "It's red";
    array[3] = "It's Black";
    array[4] = "It's green";
    Random ran = new Random();
    int r = ran.Next(array.Length);
    string token = array[r];
    Console.WriteLine(token);
}
于 2013-09-02T11:59:57.613 回答
0

你的意思是:

if (array[0] == "Blue") {
    Console.WriteLine("It's blue");
}

if (array[1] = "Violet") {
   Console.WriteLine("It's violet");
}
于 2013-09-02T11:59:49.553 回答