Convert a typed enumeration to a delimited string - CSharp System

CSharp examples for System:String Convert

Description

Convert a typed enumeration to a delimited string

Demo Code


using System.Text.RegularExpressions;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;/* ww w  .j  av  a 2s .  c  o  m*/

public class Main{
        /// <summary>
        /// Convert a typed enumeration to a delimited string
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerable"></param>
        /// <param name="separator"></param>
        /// <returns></returns>
        public static string DelimitWith<T>(this IEnumerable<T> enumerable, string separator) where T : class
        {
            return string.Join(separator, enumerable.Select(i => Equals(i, default(T)) ? null : i.ToString()).ToArray());
        }
}

Related Tutorials