. NET Foundation Enhancement 11

Source: Internet
Author: User

Review:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Net;usingSystem.Text.RegularExpressions;namespaceconsoleapplication1{classProgram {Static voidMain (string[] args) {WebClient WC=NewWebClient (); stringHTML=WC. Downloadstring ("http://search.51job.com/list/020000%252c00,%2b,%2b,%2b,%2b,%2b,asp.net,2,%2b.html?lang=c&stype=1& specialarea=00"); //<a href= "Http://search.51job.com/list/co, c,2356581,000000,10,1.html "class=" coname "target=" _blank "> Shanghai Bao Zun e-Commerce Co., Ltd. </a>MatchCollection matches = regex.matches (HTML,@"<a\s+href= "http://search.51job.com/list/co,c,\d{7},000000,10,1.html" ".+> (. +) </a>", Regexoptions.ecmascript); foreach(Match Iteminchmatches) {Console.WriteLine (item. groups[1].            Value); } Console.WriteLine (matches.            Count);        Console.readkey (); }    }}

Commissioned

A delegate is a custom data type (Class)

A delegate can be used to store a method, which is actually a new delegate object.

Different types of methods (the parameters of the method differ from the return value), to create the corresponding delegate type to store.

Delegates are generally defined in namespace.

Because the delegate is also an object, you can assign a value of NULL, so it is recommended that you use a non-null checksum before using a delegate.

Multicast delegation

Action

Action<t>

Action<t1,t2>

Fun

Public delegate T m1delegate<t> (t msg);

M1delegate<string> md=;

Meaning of the delegate:

Increase or decrease the program's extensibility, flexibility, and code injection. When you write a control, you use a lot of delegates, and when you define an event, you also use the delegate.

Lambda expression: Is the definition of a method. (is a simplified method definition, represented by an expression)

Event:

Triple Combo button

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Data;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceTriple Combo { Public Partial classUctripleclick:usercontrol { PublicUctripleclick () {InitializeComponent (); }         Publictripleclickdelegate Tripleclickhandler; intCount =0; //here is the Click event for the button        Private voidButton1_Click (Objectsender, EventArgs e) {Count++; if(Count >=3) {Count=0; //This indicates the code to be executed after the triple combo event is triggered//The code here cannot be written to death and will be determined by the user who will use the control in the future .//there is a need to execute a piece of code (a method), and the exact contents of this method are now uncertain//MessageBox.Show ("triple combo"); //using Delegates                if(tripleclickhandler!=NULL) {Tripleclickhandler (); }            }        }    }}
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceTriple Combo { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidButton1_Click (Objectsender, EventArgs e) {MessageBox.Show ("OK"); }        Private voidUctripleclick1_load (Objectsender, EventArgs e) {        }        Private voidForm1_Load (Objectsender, EventArgs e) {Uctripleclick1.tripleclickhandler=Do ; }        voidDo () {MessageBox.Show ("Triple Combo"); }    }}
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceTriple Combo { Public Partial classForm2:form { PublicForm2 () {InitializeComponent (); }        Private voidForm2_load (Objectsender, EventArgs e) {Uctripleclick1.tripleclickhandler=Do1; }        voidDo1 () {MessageBox.Show ("how R u doing?"); }    }}

Three combos with events

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Data;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceusing events to achieve triple combo { Public Partial classUctripleclick:usercontrol { PublicUctripleclick () {InitializeComponent (); }        //declaring an Event object         Public Eventtripleclickdelegate Tripleclickhandler; intCount =0; Private voidButton1_Click (Objectsender, EventArgs e) {Count++; if(Count >=3) {Count=0; //after three combos, there's an unknown code to execute .//To use event steps://1. Define a delegate//2. Define an event with this delegate (add an incident)//3. Invoke the event in the same way that the delegate is invoked                if(tripleclickhandler!=NULL) {Tripleclickhandler (); }            }        }    }     Public Delegate  voidtripleclickdelegate ();}
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceusing events to achieve triple combo { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidForm1_Load (Objectsender, EventArgs e) {            //events can only be assigned by + = or-=, which avoids the "overwrite" problem//Uctripleclick1.tripleclickhandler = Do1;Uctripleclick1.tripleclickhandler + =Uctripleclick1_tripleclickhandler; Uctripleclick1.tripleclickhandler+=Uctripleclick1_tripleclickhandler1; }        voidUctripleclick1_tripleclickhandler () {MessageBox.Show ("Event Handlers! "); }        voidUctripleclick1_tripleclickhandler1 () {MessageBox.Show ("event handlers in 2! "); }        voidDo1 () {MessageBox.Show ("Do111111111111111111111"); }        Private voidButton1_Click (Objectsender, EventArgs e) {        }    }}

. NET Foundation Enhancement 11

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.