C# variable scoping not consistent?

后端 未结 7 1596
小蘑菇
小蘑菇 2021-01-05 08:48

C# is quite nit-picking when it comes to variable scoping. How is it possible that it accepts this code:

class Program
{
    int x = 0;

    void foo()
    {         


        
7条回答
  •  长发绾君心
    2021-01-05 09:00

    Because the rule is that if a conflict exists between a local variable and a class member, the local variable has higher precedence.

提交回复
热议问题