Simple sum
Int [] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
Double numsum = numbers. sum ();
Total characters in the array
String [] words = {"Cherry", "apple", "blueberry "};
Double totalchars = words. sum (W => W. Length );
Find the minimum value
Int [] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
Int minnum = numbers. Min ();
Find the string with the least number of characters
String [] words = {"Cherry", "apple", "blueberry "};
Int shortestword = words. Min (W => W. Length );
Check whether there is at least one EI value in the array.
String [] words = {"believe", "relief", "receipt", "field "};
Bool iaftere = words. Any (W => W. Contains ("EI "));
Retrieve and sort the unique values of the Name field in the table
Datatable orders = dataset. Tables [0];
Enumerablerowcollection <datarow> query = (from order in orders. asenumerable () orderby order. field <string> ("name") Select order. field <string> ("name ")). distinct ();
Dataview view = query. asdataview ();
Gridview1.datasource = view;
Gridview1.databind ();
Group by name field in the table, total money
Datatable orders = dataset. Tables [0];
VaR query = from order in orders. asenumerable () group order by order. field <string> ("name") into G select new {names = G. key, moneys = G. sum (Order => order. field <decimal> ("money "))};
Gridview1.datasource = query. asqueryable ();
Gridview1.databind ();
Internal Connection
Datatable orders = dataset. Tables [0];
Datatable citys = dataset. Tables [1];
VaR query = from order in orders. asenumerable ()
Join city in Citys. asenumerable ()
On order. Field <string> ("name") equals city. Field <string> ("name ")
Select New
{
Name = order. Field <string> ("name "),
Money = order. Field <decimal> ("money "),
City = city. Field <string> ("city ")
};
Left join
Datatable orders = dataset. Tables [0];
Datatable citys = dataset. Tables [1];
VaR query = from order in orders. asenumerable ()
Join city in Citys. asenumerable ()
On order. Field <string> ("name") equals city. Field <string> ("name") into CITs
Select New
{
Name = order. Field <string> ("name "),
Money = order. Field <decimal> ("money "),
City = CITS. Count ()> 0? CITS. First (). Field <string> ("city "):""
};
Merge and remove duplicate items
Int [] S1 = {1, 2, 3, 4, 5 };
Int [] S2 = {3, 2, 7, 8, 10 };
VaR s3s = s1.union (S2 );
Foreach (VAR S3 in s3s)
MessageBox. Show (s3.tostring ());
Add the drag table transtest by creating a new item of the LINQ to SQL class
Modification records with transactions
Dataclassesdatacontext DB = new dataclassesdatacontext (configurationmanager. connectionstrings ["testdbconnectionstring"]. connectionstring );
DB. commandtimeout = 60;
Using (transactionscope Ts = new transactionscope ())
{
VaR records = dB. transtest. Where (P => P. Name = "Maj 'ie ");
Foreach (VAR record in Records)
{
Record. Orders = 1;
Record. Other = datetime. Now. Second. tostring ();
}
DB. submitchanges ();
TS. Complete ();
}
Add record
Dataclassesdatacontext DB = new dataclassesdatacontext (configurationmanager. connectionstrings ["testdbconnectionstring"]. connectionstring );
Transtest record = new transtest ();
Record. Other = "Iloveyou ";
DB. transtest. insertonsubmit (record );
DB. submitchanges ();