Why does this C# code throw an error: Use of unassigned local variable 'n'

前端 未结 4 571
我在风中等你
我在风中等你 2021-01-21 05:26

On MSDN, this code is posted at https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/try-catch I am unable to understand why it throws the error:

4条回答
  •  长发绾君心
    2021-01-21 06:03

    If you look at the article, you'll see the answer:

    // Error: Use of unassigned local variable 'n'.

    When you write int n; you do not initialize variable and try to use it in Console.Write(n);, so you will get compilation error: https://ideone.com/q3LXwl

提交回复
热议问题