using System.Collections.Generic;
private static String test(object search) {
foreach(var typeFunc in new Dictionary<Type,Func<String>> {
{ typeof(String), () => "Bar" },
{ typeof(Int32), () => "Foo" },
{ typeof(Boolean), () => null }
if(typeFunc.Key.IsAssignableFrom(search.GetType())) {
var result = typeFunc.Value();
if(result != null) return result;
public static void Main()
Console.WriteLine("1: " + test("a"));
Console.WriteLine("2: " + test(5));
Console.WriteLine("3: " + test(true));
Console.WriteLine("4: " + test(2.0));