Skip to content

Instantly share code, notes, and snippets.

@phillipsj
Created September 11, 2017 01:03
Show Gist options
  • Save phillipsj/24efbde38b7bb947b67c46cdd7caf636 to your computer and use it in GitHub Desktop.
Save phillipsj/24efbde38b7bb947b67c46cdd7caf636 to your computer and use it in GitHub Desktop.
C# Option 1
using System;
namespace option {
class Program {
static void Main(string[] args) {
string message;
var option = GetOption(true);
Console.WriteLine(EvaulateOption(option));
Console.ReadLine();
}
static Option GetOption(bool ifSome) {
return ifSome ? new Some<string>("Hello!") : new None() as Option;
}
static string EvaulateOption(Option option) {
switch (option) {
case Some<string> s:
return s.Value;
case None n:
return "None";
default:
return "Default";
}
}
}
abstract class Option {
}
class Some<T> : Option {
public T Value { get; }
public Some(T value) {
Value = value;
}
}
class None : Option {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment