The collation of some new syntax for. Net

Source: Internet
Author: User

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           &nbsp 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.