from LINQ statement defines range variable in LINQ query - LINQ

Q.  Which LINQ statement defines the range variable in a LINQ query?
- Published on 31 Aug 15

a. from
b. select
c. join
d. where

ANSWER: from
 
A Linq query must begin with a from clause. The from clause specifies the following:

• The data source on which the query or sub - query will be executed.
• A local range variable that represents each element in the source.
Example:
class Demo
{
static void Main()
{
Int [ ] numbers = {15, 4, 1, 3, 9, 8, 6, 7, 2, 0, 20};

var no = from num in numbers
wherenum< 4
selectnum;

foreach (intI in no)
{
Console.Write(I + “ “);
}
}
}
// Output: 1 3 2 0

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)