Default value of StringBuilder in C#

CsharpProgrammingServer Side Programming

Use the default operator to get the default value of StringBuilder.

StringBuilder str = default(StringBuilder);

Above, we have used the default keywords to get the default value.

Let us see the complete code −


 Live Demo

using System;
using System.Text;

public class Demo {
   public static void Main() {
      StringBuilder str = default(StringBuilder);
      Console.WriteLine("Default for StringBuilder = "+str);


Default for StringBuilder =

The following is the output. It shows a blank space i.e. Null.

Default for StringBuilder = Null
Updated on 22-Jun-2020 13:48:23