ArcFM Desktop Developer Guide
Chunkify<T> Method


The type of the elements of source
A sequence of values
The maximum number of elements in each chunk
Convert a sequence into a sequence of arrays (chunks) with specified length.
Syntax
'Declaration
 
<ExtensionAttribute()>
Public Shared Function Chunkify(Of T)( _
   ByVal source As IEnumerable(Of T), _
   ByVal chunkSize As Integer _
) As IEnumerable(Of IList(Of T))
'Usage
 
Dim source As IEnumerable(Of T)
Dim chunkSize As Integer
Dim value As IEnumerable(Of IList(Of T))
 
value = EnumerableExtensions.Chunkify(Of T)(source, chunkSize)
[Extension()]
public static IEnumerable<IList<T>> Chunkify<T>( 
   IEnumerable<T> source,
   int chunkSize
)

Parameters

source
A sequence of values
chunkSize
The maximum number of elements in each chunk

Type Parameters

T
The type of the elements of source

Return Value

An IEnumerable{T} whose elements are arrays
Remarks
For example, with chunk size = 3, this method converts the following sequence into a sequence with two arrays: [ 1, 2, 3, 4, 5 ] => [ [ 1, 2, 3 ], [ 4, 5 ] ]

Keep in mind, this simple implementation is not optimal for all situations. It is suitable for small sequences, yet may not be memory efficient for large sequences, and definitely not acceptable for infinite sequences.

See %% for a discussion of different approaches to chunking.

Example
For example, with chunk size = 3, this method converts the following sequence into a sequence with two arrays: [ 1, 2, 3, 4, 5 ] => [ [ 1, 2, 3 ], [ 4, 5 ] ]
Requirements

Target Platforms: Windows XP SP3 (32-bit and 64-bit), Windows 7 (32-bit and 64-bit)

Not all Operating Systems are supported on all products. Visit the ArcFM Solution Supported Versions page for full details.

See Also

Reference

EnumerableExtensions Class
EnumerableExtensions Members

 

 


Send Comment