Using System; Using System.Collections.Generic; Using System.IO; Using System.Linq; Using System.Text; Using System.Threading.Tasks;
Namespace a { public class program { static VO ID Main (string[] args) { MyClass mc = new MyClass (); //Anonymous delegation MC. Howtodoit (delegate (int a) { Console.WriteLine (a); },10); //lambda expressions MC. Howtodoit (A = Console.WriteLine (a), 10); //Data loop out list<string> strlist = new List<string> {"AA", "BB"}; strlist. ForEach (A = Console.WriteLine (a));//.net Grammar sugar foreach (var item in strlist)//general notation { Console.WriteLine (item); }
//Writing files to disk (common notation) StreamWriter SW = null; Try { SW = new StreamWriter (@ "D:\abcd.txt"); SW. WriteLine ("test"); } finally { if (sw! = NULL) sw. Dispose (); } &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; //Speak file write disk (. NET syntax sugar notation) using (var sws=new StreamWriter (@ "D:\abs.txt")) { SWS. WriteLine ("test"); } //Read file contents using (var sr= New StreamReader (@ "D:\abs.txt")) { Console.WriteLine (Sr. ReadLine ()); } //Tri-expression   var B = 3; var c = b > 9?b.tostring (): "0" +B; Console.WriteLine (c); //Two A question mark indicates that if the left side is empty, it is equal to the value on the right, and if the right is empty it equals the left value. string aa = "I am AA"; string bb = AA?? "I am BB"; Console.WriteLine (BB);
Test whether the incoming value is a number var isnum = Testnumber.isnumber ("123"); Console.WriteLine (Isnum);
Anonymous class var li = new {id= "one", name= "Little Red", age=21}; Console.WriteLine ("I Am" +li.name+ ", this year" +li.age+ "years old. ");
Console.ReadLine (); } } }
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.Threading.Tasks;
Namespace a {public class MyClass {public delegate void dosomething (int a); public void Howtodoit (DoSomething domethod,int a) {Domethod (a); }
} }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; Using System.Threading.Tasks;
Namespace A { public static class Testnumber { static private Regex tsnumber = new Regex ("\\d+");//Instantiate a regular expression //match the parameter of the descendant to the regular expression static public bool Isnumber (this string number) { & nbsp; if (string. IsNullOrEmpty (number)) { return false; } else { return Tsnumber.ismatch (number); } } }}
The collation of some new syntax for. Net