Which one is faster? Which one uses less memory?
Console.WriteLine("string1")
Console.WriteLine("string2")
Console.WriteLine("string3")
Console.WriteLine("stringNth")
or
StringBuilder output = new StringBuilder();
output.AppendLine("string1");
output.AppendLine("string2");
output.AppendLine("string3");
output.AppendLine("stringNth");
Console.WriteLine(output);
thanks,
The first.
The console class is going to buffer this to the standard output stream.
With the second option, you're trying to create your own buffer, then buffer that again.
Take it to an extreme - do this 10,000,000 times. Your StringBuilder would eventually eat up all of your memory, where the Console would just be spitting out output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With