大佬教程收集整理的这篇文章主要介绍了将List转换为C#.net中的List,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
[serializable] [XmlRootAttribute(ElementName = "UsersEntity",IsNullable = falsE)] public class UserEntity { [XmlElement(DataType="String",ElementName="UsersID")] public int UsersID { get; set; } [XmlElement(DataType = "String",ElementName = "UserName")] public String UserName { get; set; } [XmlElement(DataType = "String",ElementName = "password")] public String password { get; set; } }
然后我从Db表填充了一个记录作为数据集.然后没有foreach循环我将该数据集转换为List,如下所示
Dataset _ods= new Dataset(); //create a list of UerEntity class List<UserEntity> lstusers=new List<UserEntity>(); // populate record as dataset from DB table _ods = populateEmPDAta(); // convert List<Da@R_361_2301@w> from Dataset withou Foreach Loop List<Da@R_361_2301@w> lstRows = _ods.Tables[0].AsEnumerable().ToList();
现在我想通过使用COnvertAll方法将lstRows转换为List,如下所示:
lstusers=lstRows.ToList().ConvertAll(new Converter(ent=>ent));
但它不起作用.我怎样才能做到这一点?
lstusers = (from dr in lstRows SELEct new UserEntity { UsersId = dr.Field<int>("user_id"),UserName = dr.Field<String>("user_name"),password = dr.Field<String>("password") }).ToList();
而且,实际上,您不需要lstRows,也不需要将lstusers初始化为空列表:
var lstusers = (from dr in _ods.Tables[0].AsEnumerable() SELEct new UserEntity { UsersId = dr.Field<int>("user_id"),password = dr.Field<String>("password") }).ToList();
以上是大佬教程为你收集整理的将List转换为C#.net中的List全部内容,希望文章能够帮你解决将List转换为C#.net中的List所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。