1. Aggregate (use aggregate to create the concatenation of arrays and calculate the total product of all elements .) :
Double [] doubles = {1.7, 2.3, 1.9, 4.1, 2.9 };
Double Product = doubles. Aggregate (runningproduct, nextfactor) => runningproduct * nextfactor );
2. Aggregate heavy load (use aggregate to create a sequential account balance, from the initial balance of 100 minus the amount retrieved each time until the balance is reduced to less than 0 .) :
Double startbalancing = 100.0;
Int [] attemptedwithdrawals = {20, 10, 40, 50, 10, 70, 30 };
Double endbalance =
Attemptedwithdrawals. Aggregate (startbalance,
(Balance, nextwithdrawal) =>
(Nextwithdrawal <= balance )? (Balance-nextwithdrawal): Balance ));
3. sequenceequal (use sequenceequals to check whether all elements in the two sequences match in the same order .) :
VaR wordsa = new string [] {"Cherry", "apple", "blueberry "};
VaR wordsb = new string [] {"Cherry", "apple", "blueberry "};
Bool match = wordsa. sequenceequal (wordsb );
4. sequenceequal overload (custom comparison method ):
List <student> List = new list <student> ();
List <student> list2 = new list <student> ();
Student A = new student
{
Userid = 1,
Studentname = "Eric"
};
Student B = new student
{
Userid = 1,
Studentname = "Eric"
};
Student C = new student
{
Userid = 2,
Studentname = "laoyi"
};
List. Add ();
List. Add (B );
List. Add (C );
List2.add (C );
List2.add (B );
List2.add ();
VaR TT = List. sequenceequal (list, new studentcomparer ());
Public class student
{
Public int userid {Get; set ;}
Public String studentname {Get; set ;}
}
Custom comparison class:
Public class studentcomparer: iequalitycomparer <student>
{
Public bool equals (student X, student y)
{
Return X. userid. Equals (Y. userid );
}
Public int gethashcode (student OBJ)
{
Return obj. userid. gethashcode ();
}
}
5. Join in (left Outer Join and composite key, multiple key values are encapsulated using an anonymous type ):
List <customer> MERs = getcustomerlist ();
List <supplier> suppliers = getsupplierlist ();
VaR suppliercusts =
From sup in suppliers
Join Cust in customers on new {sup. City, sup. Country} equals New {Cust. City, Cust. Country} into CS
From C in CS. defaultifempty () // call the defaultifempty method to make it an internal link
Orderby sup. suppliername
Select New {Country = sup. Country,
City = sup. City,
Suppliername = sup. suppliername,
CompanyName = c = NULL? "(No customers)": C. companyName
};