字段初始化错误

时间:2014-01-02 17:27:32

标签: methods random field initializer

public String GetWord()
{
    string[] Words = new string[] {"Apple", "pear", "banana", "tangerine", 
    "orange", "guava", "blueberry", "strawberry", "cherry", "raspberry",
    "mango", "persimmon", "kiwi", "tomato", "avocado", "blackberry", "soursop",
    "durian", "mangosteen", "lemon", "lime", "watermelon", "peach", "apricot",
    "plum", "papaya", "nectarine", "grapefruit", "pomelo","grape", "coconut",
    "cranberry", "dates", "honeydew", "lychee", "longan", "rambutan", "pineapple",
    "pomegranate", "blackcurrant"};

    Random Ran = new Random();
    int R = Ran.Next(0, 39);
    String msg = Words[R];
    return msg;
 }

 String RandomWord = GetWord();

当我输入此代码以从列表中获取随机字时,最后一行中的GetWord()下方有一条红线,错误消息为“错误3字段初始化程序无法引用非静态字段,方法或“财产”我在这里做错了什么?

0 个答案:

没有答案