Created
October 21, 2013 15:45
-
-
Save thethomaseffect/7086037 to your computer and use it in GitHub Desktop.
Simple functional C# example
This file contains 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; | |
using Person = System.Tuple<string,string,int>; | |
namespace FunctionalCsharpExample | |
{ | |
class FunctionalCSharp | |
{ | |
static string CompareAge(Person a, Person b) | |
{ | |
if (a.Item3 == b.Item3) | |
{ | |
return "the same age as"; | |
} | |
return a.Item3 > b.Item3 ? "older than" : "younger than"; | |
} | |
static void Main(string[] args) | |
{ | |
var person1 = new Person("Thomas", "Dublin", 23); | |
var person2 = new Person("John", "Sligo", 22); | |
Console.WriteLine(person1.Item1 + " is " + CompareAge(person1,person2) + " " + person2.Item1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment