Do Join on IEnumerable and return a string - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Do Join on IEnumerable and return a string

Demo Code


using System.Reflection;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from  w  w w . j a v a2  s  .  c  om

public class Main{
  private static String DoJoin<T>(IEnumerable<T> enumerable, StringBuilder builder, string seperator)
   {
      var enumerator = enumerable.GetEnumerator();
      if (enumerator.MoveNext())
      {
         builder.Append(Convert.ToString(enumerator.Current));
      }
      
      while (enumerator.MoveNext())
      {
         builder.Append(seperator).Append(Convert.ToString(enumerator.Current));
      }
      
      return builder.ToString();
   }
}

Related Tutorials