小编ard*_*dox的帖子

C#错误:使用未分配的局部变量

错误是在for循环中引起的:

for (i = 0; i < hand.Length; i++)
{
   Console.WriteLine(hand[i]);
}
Run Code Online (Sandbox Code Playgroud)

我试图存储值,以便以后显示它们.写作线可以帮助我确保代码实际上按照我的意图运行.

其余代码供参考:*编辑:添加了一行代码

enum house //variable type for the card type
{
    Spades, Hearts, Clubs, Diamonds
}

enum cards //variable type for the cards
{
    Joker, Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King
}

class Program
{
    static void Main(string[] args)
    {

        Random rnd;
        Random rnd2;

        int i;
        int random;
        int random2;

        String[] hand;

        house randomhouse;
        cards randomcard;

        //all declared variables

        Console.WriteLine("Your hand …
Run Code Online (Sandbox Code Playgroud)

c# arrays loops unassigned-variable

6
推荐指数
1
解决办法
4693
查看次数

标签 统计

arrays ×1

c# ×1

loops ×1

unassigned-variable ×1