1. Optional parameters
You can set a default value for the method parameters, as shown in the following code: class Program {static void Main (string [] args) {Show (); Show ("cary"); Console. readLine ();} public static void Show (string msg = "") {Console. writeLine ("Hello {0}", msg );}}
2. Named ParametersThe Show method above can be called as follows: Show (msg: "cary"); when your method has multiple optional parameters of the same type (optional parameters, named parameters is particularly useful. Without naming parameters, the compiler does not know which parameter is passed.
3. Dynamic FeaturesThe dynamic keyword is used to declare a dynamic object, and then call a method or read/write attribute through the dynamic object. In the past, we used reflection, Emit, CodeDom, and other technologies at runtime. To create a dynamic object, you must use a special builder called ExpandoObject. Class Program {static void Main (string [] args) {dynamic person = new ExpandoObject (); person. name = "cary"; person. age = 25; person. showDescription = new Func <string> () => person. name + person. age); Console. writeLine (person. name + person. age + person. showDescription (); Console. readLine ();}