web analytics

Understanding Properties in C#

Options
@2016-02-01 12:54:18

Avoid explicit properties that do nothing except access a member variables. Use automatic properties instead.

//Good
public class MyClass
{
 public string Name
 {
  get;set;
 }
}


//Not Good
public class MyClass
{
 private string _name;
 
 public string Name
 {
  get
  {
   return _name;
  }
  set
  {
   _name = value;
  }
 }
}

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com