需要一些修正,下面的代码解释

时间:2016-06-17 05:39:14

标签: c# c#-3.0

class Program
{
    public static void Main(string[] args)
    {
        int x;
        if (x < 0)
        {
            Console.WriteLine("The number is negative");
        }
        else
        {
            Console.WriteLine("The number is postive");
        }
        Console.WriteLine("Value of a is : {0}", x);
        Console.ReadLine();
    }
}

获取错误使用未分配的局部变量'x'。

请帮我解决这个问题,请帮助我解决这个问题。

1 个答案:

答案 0 :(得分:2)

在检查x中的值之前,您永远不会为if分配值 分配明确的初始值,例如int x = 0;

相关问题