Skip to content

Instantly share code, notes, and snippets.

@monoman
Last active September 26, 2015 05:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monoman/1048921 to your computer and use it in GitHub Desktop.
Save monoman/1048921 to your computer and use it in GitHub Desktop.
I would do differently on a light C# example from http://www.trelford.com/blog/post/LighterCSharp.aspx
public class Person {
public Person(string name, int age) {
_name = name;
_age = age;
}
private readonly string _name;
private readonly int _age;
/// Full name
public string Name { get _name; }
/// Age in years
public int Age { get _age; }
}
/// In C# 6.0 you can do
public class Person {
public Person(string name, int age) {
Name = name;
Age = age;
}
/// Full name
public string Name { get; } // private setter implied on this auto-property
/// Age in years
public int Age { get; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment