Last active
January 15, 2016 19:24
-
-
Save miklund/3721d4e90d3c85044e93 to your computer and use it in GitHub Desktop.
2008-12-19 Purpose of constructors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: Purpose of constructors | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2008/12/20/purpose-of-constructors.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person | |
{ | |
public int ID { get; set; } | |
public string Firstname { get; set; } | |
public string Lastname { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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