StringBuilder sb = new StringBuilder(); sb.AddFormattedLine("The {0} fox jumps over the {1} dog.", "quick", "lazy"); Console.WriteLine(sb.ToString());
StringBuilder sb = new StringBuilder(); string format = "The {0} fox jumps over the {1} dog."; object[] args = { "quick", "lazy" }; sb.AddFormattedLine(format, args); Console.WriteLine(sb.ToString());
StringBuilder sb = new StringBuilder(); var data = new { Name = "John", Age = 30 }; string format = "My name is {0} and I'm {1} years old."; sb.AddFormattedLine(format, data.Name, data.Age); Console.WriteLine(sb.ToString());Output: "My name is John and I'm 30 years old." These examples demonstrate how we can append formatted text to a StringBuilder instance using the AddFormattedLine method in C#. This method is part of the System.Text package library.