/// <summary>
/// 将字符串转换成List<T>
/// </summary>
/// <typeparam name="T">类型,目前只支持int,string</typeparam>
/// <param name="str">要转换的字符串</param>
/// <param name="split">分隔符</param>
/// <returns></returns>
public static List<T> ToList<T>(this string str, string split)
{
if (!string.IsNullOrEmpty(str))
{
string[] arr = str.Split(new char[] { Convert.ToChar(split) });
if (typeof(T) == typeof(int))
{
//int[] arri = Array.ConvertAll(arr, new Converter<string, int>(StrToInt));
int[] arrInt = Array.ConvertAll<string, int>(arr, delegate(string s) { return int.Parse(s); });
List<int> list = new List<int>(arrInt);
return list as List<T>;
}
else if (typeof(T) == typeof(string))
{
List<string> list = new List<string>(arr);
return list as List<T>;
}
else
{
return new List<T>();
}
}
else
{
return new List<T>();
}
}