I am attempting to insert a string into a StringBuilder
but I get a runtime error:
Exception of type 'System.OutOfMemoryException' was thrown.
Why is this happening and how can I fix this?
My code:
Branch curBranch("properties", "");
foreach (string line in fileContents)
{
if (isKeyValuePair(line))
curBranch.Value += line + "\r\n"; // Exception of type 'System.OutOfMemoryException' was thrown.
}
Implementation of Branch
public class Branch {
private string key = null;
public StringBuilder _value = new StringBuilder(); // MUCH MORE EFFICIENT to append to. If you append to a string in C# you'll be waiting decades LITERALLY
private Dictionary <string, Branch> children = new Dictionary <string, Branch>();
public Branch(string nKey, string nValue) {
key = nKey;
_value.Append(nValue);
}
public string Key {
get { return key; }
}
public string Value {
get
{
return this._value.ToString();
}
set
{
this._value.Append(value);
}
}
}