无法访问数组元素

时间:2014-05-09 11:52:50

标签: c# arrays

这是我正在制作的简单纸牌游戏的脚本摘录。但我对数组不是很好,因为某些原因我不能让它工作。它不断回复

  

无法将方法组'Draw'转换为非委托类型'int'。

我环顾四周但似乎无法找到答案。如果您需要上下文的其余代码,我可以发布它。

// Generates three cards with two random values on each then 
stores them inside the usercardvalues array 



    int[] UserCardValues = new int[3] {PlayDeck.Draw, PlayDeck.Draw, PlayDeck.Draw};
    Console.WriteLine(UserName + "'s Damage / Health values are");                                                                                                 
    Console.WriteLine("Card 1: {0}", UserCardValues[0]);
    Console.WriteLine("Card 2: {0}", UserCardValues[1]);
    Console.WriteLine("Card 3: {0}", UserCardValues[2]);
    Console.WriteLine();
    Console.WriteLine("Hit enter to continue!");
    Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~");
    Console.ReadLine();

// Gets and prints the dealers card from the random generator
    int[] DealerCardValues = new int[3] {PlayDeck.Draw, PlayDeck.Draw, PlayDeck.Draw}; 
    Console.WriteLine("The Dealers Damage / Health Values are");
    Console.WriteLine("Card 1: {0}", DealerCardValues[0]);
    Console.WriteLine("Card 2: {0}", DealerCardValues[1]);
    Console.WriteLine("Card 3: {0}", DealerCardValues[2]);                                         
    Console.WriteLine();
    Console.WriteLine("Hit enter to continue!");
    Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~");
    Console.ReadLine();

1 个答案:

答案 0 :(得分:4)

由于Draw是一种方法,并且错误很明显,所以你应该像方法一样使用它

PlayDeck.Draw()

而不喜欢:

PlayDeck.Draw

记得Draw()需要returnint