namespace System.Linq { public static class IdSExtensions { /// <summary> /// 把list集合中的某一个字段的数值,变成一个字符串 /// </summary> /// <typeparam name="TSource">数据源的类型</typeparam> /// <param name="list">数据源</param> /// <param name="Name">类型变量的名称</param> /// <param name="FenGeFu">用来分割字符串的一个标识</param> /// <returns></returns> public static string ToStringIdS<TSource>(this IEnumerable<TSource> list, string Name, string FenGeFu) { string IdS = ""; string value = ""; foreach (var item in list) { value = typeof(TSource).GetProperty(Name).GetValue(item).ToString(); IdS += value + FenGeFu; } if (IdS.Length > 0) { IdS = IdS.Substring(0, IdS.Length - 1); } return IdS; } } }