I'm trying to make a simple extension method, for the String class, which will allow me to supply text to be appended to an existing string variable with a newline character included:
string myStr = "Line 1";
myStr.AppendLine("Line 2");
This code should yield a string that prints as follows
Line 1
Line 2
Here's the code I wrote for it:
public static class StringExtensions
{
public static void appendLine(this String str, string text)
{
str = str + text + Environment.NewLine;
}
}
But when I call the code, the new text never gets appended to the original instance variable. How to achieve that?