Cook Computing

 

«  Field Names  »

Thursday 10 March 2005

Eric Gunnerson discusses field names in C# code. As mentioned before my preference is his option #2, underscore ("string _name"). One reason is that you don't have to think so much when naming constructor parameters used to initialize member variables: the name of the parameter can be the name of the member minus the underscore prefix:

class MyClass
{
  string _foo;

  public MyClass(string foo)
  {
    _foo = foo;
  }
  // ...
}
Posted by at 06:30 AM. Permalink.