C# string format methods

In this source code example, we will see three different methods to format strings in C#.

C# string format methods

In the following example, we use string.Format(), Console.WriteLine(), and StringBuilder.AppendFormat() to format strings.
using System;
using System.Text;

namespace MyApplication
  class Program
    static void Main(string[] args)
     	    var msg = string.Format("There are {0} owls", 5);

            Console.WriteLine("There are {0} eagles", 3);

            var builder = new StringBuilder();
            builder.AppendFormat("There are {0} hawks", 4);


There are 5 owls

There are 3 eagles

There are 4 hawks

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course