latest Post

LINQ Query Syntax

LINQ query syntax:

from <range variable> in <IEnumerable<T> or IQueryable<T> Collection>

<Standard Query Operators> <lambda expression>

<select or groupBy operator> <result formation>
Example:
// string collection
IList<string> stringList = new List<string>() { 
    "C#",
    "VB.NET",
    "C++",
    "MVC" ,
    "Java" 
};

// LINQ Query Syntax
var result = from s in stringList
            where s.Contains("Java") 
            select s;
Query syntax starts with a From clause followed by a Range variable. The From clause is structured like "From rangeVariableName in IEnumerablecollection". In English, this means, from each object in the collection. It is similar to a foreach loop: foreach(Student s in studentList).
After the From clause, you can use different Standard Query Operators to filter, group, join elements of the collection. There are around 50 Standard Query Operators available in LINQ. In the above figure, we have used "where" operator (aka clause) followed by a condition. This condition is generally expressed using lambda expression.
LINQ query syntax always ends with a Select or Group clause. The Select clause is used to shape the data. You can select the whole object as it is or only some properties of it. In the above example, we selected the each resulted string elements.

About Mallikarjun A

Mallikarjun A
Recommended Posts × +

1 comments:

  1. Online casino site in Singapore. Best Online Casinos
    Singapore casino site 메리트 카지노 is an online gambling site that has become popular due to its friendly and easy 메리트 카지노 고객센터 to use interface, casino games available for real money choegocasino

    ReplyDelete