小编Sat*_*der的帖子

为什么这个C#代码会抛出错误:使用未分配的局部变量'n'

在MSDN上,此代码发布在https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/try-catch 我无法理解为什么它会抛出错误:

使用未分配的局部变量'n'.

static void Main()   
{  
    int n;  

    try   
    {  
        // Do not initialize this variable here.  
        n = 123;  
    }  
    catch  
    {  
    }  

    // Error: Use of unassigned local variable 'n'.  
    Console.Write(n);  
}
Run Code Online (Sandbox Code Playgroud)

c#

3
推荐指数
2
解决办法
582
查看次数

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

algorithm ×1

branch-and-bound ×1

c# ×1