Permalink
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (61 sloc) 2.97 KB
title ms.date ms.prod ms.reviewer ms.suite ms.technology ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author translation.priority.ht
Take Clause (Visual Basic)
2015-07-20
.net
devlang-visual-basic
article
vb.QueryTake
VB
Take statement
queries [Visual Basic], Take
Take clause
77bf87b2-1476-4456-957f-fee922fbad8c
15
dotnet-bot
dotnetcontent
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

Take Clause (Visual Basic)

Returns a specified number of contiguous elements from the start of a collection.

Syntax

Take count  

Parts

count
Required. A value or an expression that evaluates to the number of elements of the sequence to return.

Remarks

The Take clause causes a query to include a specified number of contiguous elements from the start of a results list. The number of elements to include is specified by the count parameter.

You can use the Take clause with the Skip clause to return a range of data from any segment of a query. To do this, pass the index of the first element of the range to the Skip clause and the size of the range to the Take clause. In this case, the Take clause must be specified after the Skip clause.

When you use the Take clause in a query, you may also need to ensure that the results are returned in an order that will enable the Take clause to include the intended results. For more information about ordering query results, see Order By Clause.

You can use the TakeWhile clause to specify that only certain elements be returned, depending on a supplied condition.

Example

The following code example uses the Take clause together with the Skip clause to return data from a query in pages. The GetCustomers function uses the Skip clause to bypass the customers in the list until the supplied starting index value, and uses the Take clause to return a page of customers starting from that index value.

[!code-vbVbSimpleQuerySamples#1]

See Also

Introduction to LINQ in Visual Basic
Queries
Select Clause
From Clause
Order By Clause
Take While Clause
Skip Clause