C# variable scoping not consistent?

后端 未结 7 1612
小蘑菇
小蘑菇 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:08

    This is not ambiguous the local will be the variable that is assumed to reffed to in your function. If you need to get the class variable this.x allows the name resolution.

提交回复
热议问题