Skip to content

Instantly share code, notes, and snippets.

@leongersing
Created December 16, 2009 16:52
Show Gist options
  • Save leongersing/257978 to your computer and use it in GitHub Desktop.
Save leongersing/257978 to your computer and use it in GitHub Desktop.
C# version of a class and it's instances (objects)
public class Person{
public string Name{get;set;}
public string Email{get;set;}
public int Age{get;set;}
public string Sex{get;set;}
}
public class Man : Person{
public Man{
Sex = "male";
}
}
public class Woman : Person{
public Man{
Sex = "female";
}
}
Person person = new Person();
person.Name = "Leon";
person.Email = "foo@foo.com";
person.Age = 32;
Man leon = new Man(Name="Leon", Email="foo@foo.com", Age=32);
Console.WriteLine(leon.Sex); // it's a boy! :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment