Convert IEnumerable To the separated string. - CSharp System

CSharp examples for System:DateTime Convert

Description

Convert IEnumerable To the separated string.

Demo Code


using System.Web;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Extensions;
using System.Web.Mvc;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;//from  w  w  w . jav a2s  . c  o  m

public class Main{
        /// <summary>
        /// To the separated string.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items">The items.</param>
        /// <param name="Separator">The separator.</param>
        /// <returns></returns>
        public static string ToSeparatedString<T>(this IEnumerable<T> items, string Separator = ",")
        {
            return items.Any<T>() ? string.Join(Separator, items.Where(w => w.TryCast<string>().IsNotNullOrEmpty()).Distinct()).Trim(Separator.ToCharArray().First()) : null;
        }
        /// <summary>
        /// To the separated string.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items">The items.</param>
        /// <param name="Separator">The separator.</param>
        /// <returns></returns>
        public static string ToSeparatedString<T>(this List<T> items, string Separator = ",")
        {
            return items.Any<T>() ? string.Join(Separator, items.Where(w => w.TryCast<string>().IsNotNullOrEmpty()).Distinct()).Trim(Separator.ToCharArray().First()) : null;
        }
}

Related Tutorials