using System; namespace DynamicExamples { class Program { static void Main(string[] args) { ExampleClass ec = new ExampleClass(); Console.WriteLine(ec.exampleMethod(10)); Console.WriteLine(ec.exampleMethod("value")); // The following line causes a compiler error because exampleMethod // takes only one argument. //Console.WriteLine(ec.exampleMethod(10, 4)); dynamic dynamic_ec = new ExampleClass(); Console.WriteLine(dynamic_ec.exampleMethod(10)); // Because dynamic_ec is dynamic, the following call to exampleMethod // with two arguments does not produce an error at compile time. // However, itdoes cause a run-time error. //Console.WriteLine(dynamic_ec.exampleMethod(10, 4)); } } class ExampleClass { static dynamic field; dynamic prop { get; set; } public dynamic exampleMethod(dynamic d) { dynamic local = "Local variable"; int two = 2; if (d is int) { return local; } else { return two; } } } } // Results: // Local variable // 2 // Local variable