(20140714 jobs) the super mandatory killer is extracted from small tricks! C # Basic Skills

Source: Internet
Author: User

Homework requires a summary of the basic knowledge you have learned before. It can be said that learning is messy and messy! Here I have written several key points mentioned by stone, such as generics and delegation.

 

 

 

1 using system; 2 using system. collections. generic; 3 using system. LINQ; 4 using system. reflection; 5 using system. text; 6 using system. threading. tasks; 7 8 namespace consoleapplication1 9 {10 class program11 {12 static void main (string [] ARGs) 13 {14 console. foregroundcolor = consolecolor. yellow; 15 listtest (); 16 stringtest (); 17 console. writeline ("use delegate ----------"); 18 testhandler th = new testhandler (listtest); 19 th + = stringtest; 20 th-= stringtest; // ① 21 // th-= listtest; // ② 22 23 th. invoke (); // ③ 24 console. read (); 25} 26 27 // <summary> transaction usage </Summary> 28 delegate void testhandler (); 29 30 // save data 31 static list <string> List = new list <string> (); 32 // <summary> enumeration, generics, and list values after running </Summary> 33 public static void listtest () 34 {35 console. writeline ("---------------- enumeration -----------------"); 36 console. writeline ("output typecode:"); 37 foreach (string name in Enum. getnames (typeof (typecode) 38 {39 console. writeline (name + "\ t"); 40 list. add (name); 41} 42} 43 // <summary> string </Summary> 44 public static void stringtest () 45 {46 console. writeline ("---------------- string -----------------"); 47 list = List. where (I => I. contains ("int ")). tolist <string> (); 48 console. writeline ("string processing: \ r \ n each int type retains the last 2 characters"); 49 // foreach (VAR item in List) 50 // {51 // console. writeline (item. substring (item. length-2); 52 //} 53 list. foreach (x => 54 {55 console. writeline (X. substring (X. length-2); 56 57}); 58 59} 60} 61}

What I did in this job is to obtain the enumerated values in the typecode class for subsequent testing data. Of course, all of them are strings.
Process the string, locate the item that contains "int", and extract the last two characters (DIGIT) from the output.
The running result is as follows:

 

The understanding of delegation is still stuck in the concept that it is a "method container", and the specific usage is still being learned.

th -= StringTest; // ① // th -= ListTest; // ②

  

Code above: Comment out ① cancel annotation ② the running result is blank
Cancel comments for both, and an exception is reported at ③.

Some of the knowledge points mentioned in this assignment are:
Loop, generics, enumeration, delegation, string truncation, and lambda expressions.

Thank you for your criticism.

They are all extracted from small tricks!

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.