Skip to content

Instantly share code, notes, and snippets.

@miklund
Last active January 15, 2016 19:24
Show Gist options
  • Save miklund/3721d4e90d3c85044e93 to your computer and use it in GitHub Desktop.
Save miklund/3721d4e90d3c85044e93 to your computer and use it in GitHub Desktop.
2008-12-19 Purpose of constructors
# Title: Purpose of constructors
# Author: Mikael Lundin
# Link: http://blog.mikaellundin.name/2008/12/20/purpose-of-constructors.html
Person person = new Person
{
Firstname = "John",
Lastname = "Doe",
Address = new Address
{
StreetName = "Last Hope",
Zip = 42,
City = "Vladivostok"
},
PhoneNumbers = new string[]
{
"123-321",
"+45 234 234",
"3333333"
}
};
public class Person
{
public int ID { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
}
public class Person
{
private int id;
public Person(int id)
{
System.Diagnostics.Debug.Assert(id > -1, "Class Person was initialized with ID < 0");
this.id = id;
}
public int ID { get { return this.id; } }
public string Firstname { get; set; }
public string Lastname { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment