3332130
is a large number to store in memory, you should not hold such a big collection in memory.
Being said that, Let's try to optimize this.
Dictionary<string, StringBuilder>() d = new Dictionary<string, StringBuilder>();
StringBuilder builder;
if (d.TryGetValue(dKey, out builder))
{
builder.Append(",");
builder.Append(ctr);
}
else
{
d.Add(dKey, new StringBuilder(ctr.ToString()));
}
- String concatenation in tight loop is awfully slow, use
StringBuilder
instead - Use
TryGetValue
which avoids you to calldValue = d[dKey];
.
I believe this should increase performance significantly.