Convert Array To String - CSharp System

CSharp examples for System:Array Convert

Description

Convert Array To String

Demo Code


using System.Text;

public class Main{
        public static string ConvertToString<T>(T[] array)
    {//from  ww  w  .j a va  2 s . com
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < array.Length; i++)
        {
            if (i == 0)
            {
                sb.AppendFormat("[{0}", array[i]);
            }
            else
            {
                sb.AppendFormat(", {0}", array[i]);
            }

            if (i == array.Length-1)
            {
                sb.Append("]");
            }
        }

        return sb.ToString();
    }
}

Related Tutorials