You can use the LINQ First()
method to select the first element or the first element that satisfies a given condition within a collection.
To select the first X number of entries in a collection, you can use the Take()
method in combination with First()
. Here's how you can do it:
main.cs236 chars9 lines
This will output 1
in the console, which is the first element of the numbers
collection after taking 5 elements.
gistlibby LogSnag