Skip to content

Instantly share code, notes, and snippets.

@thethomaseffect
Created October 21, 2013 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thethomaseffect/7086051 to your computer and use it in GitHub Desktop.
Save thethomaseffect/7086051 to your computer and use it in GitHub Desktop.
Simple OOP example in C#
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