Cook Computing

Field Names

March 9, 2005 Written by Charles Cook

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;
  }
  // ...
}