Where:
Using where we can filter the records in a particular set based on some condition.
EX:
For example take one array set of numbers
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
Suppose if we want to find the elements which are less than 5 in the above set.How to achieve this using where condition in LINQ.
Declare one variable and using the where condition to above set ,store the values in variable.
var lowNums = from n in numbers where n < 5 select n;
Now lowNums is having values less than 5
code:
public void whereSimple1()
{
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var lowNums = from n in numbers where n < 5 select n;
Console.WriteLine("Numbers <5:");
foreach (var x in lowNums)
{
Console.WriteLine(x);
}
Console.ReadKey();
}
output:
Numbers <5:
4
1
3
2
0
Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts
Tuesday, December 11, 2012
Types of Operators in LINQ
The following types of Operators existed in LINQ
- Restriction Operators
- Projection Operators
- Partitioning Operators
- Ordering Operators
- Grouping Operators
- Set Operators
- Conversion Operators
- Element Operators
- Generation Operators
- Quantifiers
- Aggregate Operators
- Miscellaneous Operators
- Custom Sequence Operators
- Query Execution
- Query Execution
Subscribe to:
Posts (Atom)