Created
October 21, 2013 15:45
-
-
Save thethomaseffect/7086051 to your computer and use it in GitHub Desktop.
Simple OOP example in C#
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
using System; | |
namespace OOCSharpExample | |
{ | |
internal class OOCSharp | |
{ | |
private static void Main(string[] args) | |
{ | |
var person1 = new Person("Thomas", "Dublin", 23); | |
var person2 = new Person("John", "Sligo", 22); | |
Console.WriteLine(person1.Name + " is " + person1.CompareAge(person2) + " " + person2.Name); | |
} | |
} | |
internal class Person | |
{ | |
public string Name { get; set; } | |
public string Location { get; set; } | |
public int Age { get; set; } | |
public Person(string name, string location, int age) | |
{ | |
Name = name; | |
Location = location; | |
Age = age; | |
} | |
public string CompareAge(Person p) | |
{ | |
if (Age == p.Age) | |
{ | |
return "the same age as"; | |
} | |
return Age > p.Age ? "older than" : "younger than"; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment