description | title | ms.date | dev_langs | ms.assetid | ||
---|---|---|---|---|---|---|
Learn more about: Return the First Element in a Sequence |
Return the First Element in a Sequence |
03/30/2017 |
|
ccdc3777-b2c2-44e3-a627-abef8d79a555 |
Use the xref:System.Linq.Enumerable.First%2A operator to return the first element in a sequence. Queries that use xref:System.Linq.Enumerable.First%2A are executed immediately.
Note
[!INCLUDEvbtecdlinq] does not support the xref:System.Linq.Enumerable.Last%2A operator.
The following code finds the first Shipper
in a table:
If you run this query against the Northwind sample database, the results are
ID = 1, Company = Speedy Express
.
[!code-csharpDLinqQueryExamples#14] [!code-vbDLinqQueryExamples#14]
The following code finds the single Customer
that has the CustomerID
BONAP.
If you run this query against the Northwind sample database, the results are ID = BONAP, Contact = Laurence Lebihan
.
[!code-csharpDLinqQueryExamples#15] [!code-vbDLinqQueryExamples#15]