Partitioning and Element Operations
Learn the basics of partitioning and element operations in LINQ.
Overview
This lesson reviews partitioning and element operations in LINQ. These operations are not applicable using the query syntax. Therefore, all the examples in this lesson are done with query methods.
Partitioning operations
In LINQ, partitioning refers to the operation of dividing a source sequence into two or more sections and then returning one of the sections.
The illustration above shows the results of three different partitioning operations on a sequence of characters. Note the following about these operations:
-
The first operation returns the first three elements of the sequence.
-
The second operation skips the first three elements and returns the remaining elements.
-
The third operation skips the first two elements of the sequence and returns the next two.
We’ll demonstrate partitioning operations using the C# console project below:
{ "version": "0.2.0", "configurations": [ { // Use IntelliSense to find out which attributes exist for C# debugging // Use hover for the description of the existing attributes // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md "name": ".NET Core Launch (console)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/bin/Debug/net6.0/QueryData.dll", "args": [], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console "console": "internalConsole", "stopAtEntry": false }, { "name": ".NET Core Attach", "type": "coreclr", "request": "attach" } ] }
The project utilizes a collection of albums highlighted on lines 8–20 ...
Get hands-on with 1400+ tech skills courses.