C# 需要一些下面的代码解释更正 类程序 { 公共静态void Main(字符串[]args) { int x; if(x

C# 需要一些下面的代码解释更正 类程序 { 公共静态void Main(字符串[]args) { int x; if(x,c#,c#-3.0,C#,C# 3.0,获取未赋值局部变量“x”的错误用法 请帮我解决这个问题。在检查if中的值之前,您从未分配x值 指定一个明确的初始值,如intx=0谢谢非常有用如果有帮助,请接受它作为答案 class Program { public static void Main(string[] args) { int x; if (x < 0) { Console.WriteLine("The number is negativ

获取未赋值局部变量“x”的错误用法


请帮我解决这个问题。在检查
if
中的
值之前,您从未分配
x

指定一个明确的初始值,如
intx=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();
    }
}