I have a dictionary that looks like this:
Dictionary<string, int> supplierStockLevels = new Dictionary<string, int>()
{
{ "ABCD1", 1},
{ "ABCD2", 2},
{ "ABCD3", 2},
{ "ABCD4", 1},
{ "ABCD5", 3}
};
I want to pluck a chunk of 2 records at a time out of this dictionary and process it.
In PHP, I normally do something like this:
$supplierStockLevels =
[
'ABCD1' => 1,
'ABCD2' => 2,
'ABCD3' => 2,
'ABCD4' => 1,
'ABCD5' => 3
];
$preserveKeys = true;
$batchSize = 2;
foreach (array_chunk($supplierStockLevels, $batchSize, $preserveKeys) as $batch)
{
// Do something
var_dump($batch);
}
Outputs:
How can I achieve the same C# .NET (4.5.x)?