In addition to the above, it's interesting to note that you can get exceptions if you use IQueryable
instead of IEnumerable
:
The following works fine if products
is an IEnumerable
:
products.Skip(-4);
However if products
is an IQueryable
and it's trying to access records from a DB table, then you'll get this error:
The offset specified in a OFFSET clause may not be negative.
This is because the following query was constructed:
SELECT [p].[ProductId]
FROM [Products] AS [p]
ORDER BY (SELECT 1)
OFFSET @__p_0 ROWS
and OFFSET can't have a negative value.