Search code examples
programming-languagesnaming-conventions

Why do we use _ in variable names?


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


Solution

  • 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;
       }
    }