Returns a single string, representing the ToString values of the objects in the given collection. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:ICollection

Description

Returns a single string, representing the ToString values of the objects in the given collection.

Demo Code


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

public class Main{
        /// <summary>
      /// Returns a single string, representing the ToString values of the objects in the given collection.
      /// </summary>
      public static string JoinToString<T>(this IEnumerable<T> collection)
      {
         if (collection == null)
            return "null";

         if (collection.Count() <= 0)
            return "empty";

         return collection.Select(o => o.ToString()).JoinNonEmpty(", ");
      }
}

Related Tutorials