Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 1.67 KB

return-the-first-element-in-a-sequence.md

File metadata and controls

40 lines (27 loc) · 1.67 KB
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
csharp
vb
ccdc3777-b2c2-44e3-a627-abef8d79a555

Return the First Element in a Sequence

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.

Example 1

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]

Example 2

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]

See also