C# StringBuilder Append(Object)

Description

StringBuilder Append(Object) Appends the string representation of a specified object to this instance.

Syntax

StringBuilder.Append(Object) has the following syntax.


public StringBuilder Append(
  Object value
)

Parameters

StringBuilder.Append(Object) has the following parameters.

  • value - The object to append.

Returns

StringBuilder.Append(Object) method returns A reference to this instance after the append operation has completed.

Example

Appends the string representation of a specified object to this instance.


using System;/*w  w w .  j  a  v a2  s .c o  m*/

public class Dog
{
    private string dogName;

    public Dog(string name)
    {
        this.dogName = name;
    }
    public override string ToString()
    {
        return this.dogName;
    }
}

public class Example
{
    public static void Main()
    {
        Dog dog1 = new Dog("A");
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(dog1).Append(", Breed: ").Append(dog1.GetType());
        Console.WriteLine(sb);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding