Finished Query Syntax vs. Method Syntax

2_linq_and_csharp
jason.zhu 2021-02-24 16:17:42 +11:00
parent 066f46a48c
commit ea26766337
1 changed files with 21 additions and 0 deletions

View File

@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
namespace Features
{
@ -54,6 +55,26 @@ namespace Features
{
Console.WriteLine(employee.Name);
}
// LINQ (Method syntax)
var query = developers.Where(e => e.Name.Length == 5)
.OrderBy(e => e.Name);
// LINQ (Query syntax)
var query2 = from developer in developers
where developer.Name.Length == 5
orderby developer.Name descending
select developer;
foreach (var employee in query)
{
Console.WriteLine(employee.Name);
}
foreach (var employee in query2)
{
Console.WriteLine(employee.Name);
}
}
}
}