C # detail-based lambda, LINQ, and anonymous methods

Source: Internet
Author: User
View Code To survive forever
I will not explain it. It is very easy. I have not studied it carefully. I will write it down here and study it in depth later. Using System;
Using System. Collections. Generic;
Using System. collections;
Using System. LINQ;
Using System. text;

Namespace Landpy
{
Class Starter
{
Delegate   Int Add ( Int I, Int J );
Delegate   Bool Compare ( Int I, Int J );
Delegate   Void Nonamemethod ( String Name );
Static   Void Main ()
{
Add add = (X, y) => X + Y;
Console. writeline (Add. Invoke ( 1 , 2 ));
Compare compare = (I, j) => I = J;
Console. writeline (compare. Invoke ( 1 , 2 ));
Console. writeline (compare. Invoke ( 1 , 1 ));
Nonamemethod =
Delegate ( String Name)
{
Console. writeline (string. Format ( " Hello {0 }! " , Name ));
};
Action < Int > Hello =   Delegate ( Int I)
{
For ( Int J =   0 ; J < I; j ++ )
{
Console. writeline ( " Hello " );
}
};
Nonamemethod. Invoke ( " Landpy " );
Hello. Invoke ( 3 );

String [] Names = { " ++ Landpy " , " Pxl " , " Ljc " , " Baby " };
// Lambda writing
VaR quereynamestwo = Names. Where (n => N. Length =   3 ). Select (n => N. substring ( 2 )); // . Select (n => N. Name );

// Writing of LINQ
VaR quereynames = From n In Names
Where N. Length =   3
Select N;

Foreach(StringNameInQuereynames)
{
Console. writeline (name );
}

Foreach(StringNameInQuereynamestwo)
{
Console. writeline (name );
}

Arraylist employees= NewArraylist ();

For ( Int I =   0 ; I <   10 ; I ++ )
{
Employee =   New Employee ();
Employee. Name =   " Name "   + I. tostring ();
Employee. Age = I;
Employees. Add (employee );
}

Employee [] employeesarray=(Employee []) employees. toarray (Typeof(Employee ));

VaR es = Employeesarray. Where (n => N. Age >   4 );
Foreach (Employee employeetmp In ES)
{< br> console. writeline (employeetmp. name);
}< BR >}

class employee
{< br> Public string name
{< br> Get ;< br> set ;< BR >}

Public int age
{< br> Get ;< br> set ;< BR >}

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.