StringBuilder sb = new StringBuilder(); sb.AppendFormat("My name is {0} and I'm {1} years old.", "John", 25); Console.WriteLine(sb.ToString());
double price = 9.99; int quantity = 3; StringBuilder sb = new StringBuilder(); sb.AppendFormat("You bought {0} item(s) for a total of ${1}.", quantity, price * quantity); Console.WriteLine(sb.ToString());Description: In this example, the AppendFormat method is used to format a string that includes the values of "quantity" and the "price * quantity" calculation. These values are then appended to the StringBuilder object, resulting in the final output of "You bought 3 item(s) for a total of $29.97.". Overall, System AppendFormat is a useful method for formatting strings in C# and is included in the System.Text library.