Convert String To the list. - CSharp System

CSharp examples for System:DateTime Convert

Description

Convert String To the list.

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.  ja  v  a 2s. c  o m

public class Main{
        /// <summary>
        /// To the list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="str">The string.</param>
        /// <param name="Separator">The separator.</param>
        /// <returns></returns>
        public static List<T> ToList<T>(this string str, string Separator = ",")
        {
            if (str.IsNullOrEmpty()) return new List<T>();
            return str.Split(new string[] { Separator }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.TryCast<T>()).ToList();

        }
}

Related Tutorials