C# variable scoping not consistent?

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

    Thats normal.

    In constructors I often use the same.

    public Person(string name) {
      this.name = name;
    }
    

    Else it would be not possible to declare method parameters which are named like member variables.

提交回复
热议问题