Can someone please explain why I'm getting the following error from the following piece of code.
System.ArgumentOutOfRangeException: capacity was less than the current size. (Parameter 'value')
I'm trying to take a semi-colon separated list which is then further comma separated.
The channelCodeToBoxesMapping parameter value expected would be something like this 01,0;02,1;03,1;05,1;06,0;07,1;08,1
.
Code:
private bool DetermineWhetherInSingleBoxModeFromChannelCodeMappings(string channelCodeToBoxesMapping)
{
this.boxes.Clear();
if (string.IsNullOrWhiteSpace(channelCodeToBoxesMapping))
{
return false;
}
var channelCodeAndBoxPairs = channelCodeToBoxesMapping.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var pair in channelCodeAndBoxPairs)
{
var channelCodeAndBoxSplit = pair.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (channelCodeAndBoxSplit.Length != 2)
{
continue;
}
this.boxes.Add((BoxCount.Boxes)Convert.ToInt16(channelCodeAndBoxSplit[1]));
}
return this.boxes.Distinct().Count() == 1;
}
Notes:
this.boxes
is a list of enums i.e. List<BoxCount.Boxes>
.