- Obtain the data sources(s)
- Create the query
- Declare variable var query = the following
- From variable Name in obtained data Source [//Declaration]
- Where variable name. Property == or > or < or any operator against any value [// criteria and filtering]
- Orderby variable name. Property, variable name. Property [//sorting]
- Select (variable name or variable name * 10 (any expression) or new { property1= val1 , property2 = val2 } (anonymous type) [// projection]
- Execute the query
- ToList()
- ToArraay()
- Foreach and access the query result
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var files = new DirectoryInfo(@"c:\\").GetFiles();
var query = from file in files
where file.Length > 0
orderby file.Name, file.Length
select new
{
Name = file.Name,
Length = file.Length,
CreatedDate = file.CreationTime
};
var my = query.ToList();
foreach (var myFileInfo in query)
{
Console.WriteLine(myFileInfo.Name);
}