IEnumerable To String - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

IEnumerable To String

Demo Code


using System.Text;
using System.Reflection;
using System.Collections;
using System;/*  w w  w . j  av  a2 s.c o m*/

public class Main{
        public static string ToString(IEnumerable c)
        {
            StringBuilder sb = new StringBuilder("[");

            IEnumerator e = c.GetEnumerator();

            if (e.MoveNext())
            {
                sb.Append(e.Current.ToString());

                while (e.MoveNext())
                {
                    sb.Append(", ");
                    sb.Append(e.Current.ToString());
                }
            }

            sb.Append(']');

            return sb.ToString();
        }
}

Related Tutorials