// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; namespace E { public class Program { // order important // case ... when public static void Test(object o) { switch(o) { case int vi: Console.WriteLine(vi); break; case string vs: Console.WriteLine(vs); break; } } public static void Main(string[] args) { Test(123); Test("ABC"); } } }