If you really want to stick with a StringBuilder you can use an extension method to give you a List and then you can access it with an element number.
internal static class ExtensionMethods
{
public static List<string> ToList(this StringBuilder stringBuilder)
{
return stringBuilder.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList();
}
}
You can then access it by calling the ToList() method.
int i = 0;
StringBuilder SB = new StringBuilder();
while (i++ != 1000000)
{
SB.AppendLine(i.ToString());
}
string ChosenElement = SB.ToList()[1000];
StringBuilderis the wrong object that you should be using, what are you trying to do?StringBuilder", causing you to have the problem Y: "But now I can't get separate strings back from theStringBuilder". Explain your original problem X.Appendwith a separator<space>(may be). and split withSplit(separator)and showelements[0]where elements is the array of splits.List<>option but may be OP would like to stick withStringBuilderfor no reason. One has the right to provide alternatives which may/may not be buggy for others.