Method Syntax
Let's learn about method syntax.
In previous code, we learn about query syntax as shown code below.
from b in birds where b.Color == "Red" select b
Method syntax reduces our codes to look like this.
birds.Where(b => b.Color == "Red");
In grouping and orderby syntax.
// Query Syntax
from b in birds orderby b.Color select b.Name
// Method Syntax
birds.OrderBy(b => b.Color);
//or
birds.OrderyByDescending(b => b.Color);
Other properties in method syntax.
birds.Where(b => b.Color==”red”).OrderBy(b => b.name);
// ordering birds by Name
birds.OrderBy(b => b.name).ThenBy(b => b.sightings);
// ordering birds by name and sightings
birds.Select(b => new { b.Name, B.Color});
// selecting the birds
You are free to choose between query syntax and method syntax. But, it is good to be comfortable in both syntax.