Why do we use _ in variable names?

前端 未结 11 1893
一生所求
一生所求 2020-12-25 11:26

I have seen variables like _ image and was wondering what _ meant?

11条回答
  •  一个人的身影
    2020-12-25 12:04

    It doesn't mean anything. It is rather a common naming convention for private member variables to keep them separated from methods and public properties. For example:

    class Foo
    {
       private int _counter;
    
       public int GetCounter()
       {
          return _counter;
       }
    
       public int SetCounter(int counter)
       {
          _counter = counter;
       }
    }
    

提交回复
热议问题