Skip to content

Instantly share code, notes, and snippets.

@dtryon
Created April 22, 2012 22:24
Show Gist options
  • Save dtryon/2467312 to your computer and use it in GitHub Desktop.
Save dtryon/2467312 to your computer and use it in GitHub Desktop.
Func as selector
using System;
public class Program
{
public static void Main()
{
Brush brush = new Brush();
brush.ChooseColor(c => c);
Console.WriteLine("Choose Default: {0}", brush.Color);
brush.ChooseColor(c => Color.Red);
Console.WriteLine("Color Selected: {0}", brush.Color);
Console.WriteLine("Press <enter> to close.");
Console.ReadLine();
}
}
public enum Color
{
None,
Red,
Orange,
Yellow,
Green,
Blue,
Violet
}
public class Brush
{
private Color color;
public Color Color { get { return this.color; } }
public void ChooseColor(Func<Color, Color> colorSelector)
{
// Yellow is the default
this.color = colorSelector(Color.Yellow);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment