创建列表< CustomObject>来自List< string> [英] Create List<CustomObject> from List<string>

查看:60
本文介绍了创建列表< CustomObject>来自List< string>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CustomObject,例如,用以下服装定义:

I have a CustomObject, say defined with following attibutes:

string Name {get;set;}
string EmailAddress{get;set;}

此外,我还有一个单独的List<string>,其中包含所有名称"

Also, I have a separate List<string> that contains all 'names'

我想用名称从List<string> names分配的每个CustomObject填充List<CustomObject>.

I want to populate List<CustomObject> with each CustomObject having its name assigned from List<string> names.

如何使用Linq实现此目的?

How can I achive this using Linq?

推荐答案

var strList = new List<string>();
var coList = strList.Select(item => new CustomObject() {Name = item}).ToList();

这篇关于创建列表&lt; CustomObject&gt;来自List&lt; string&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆