c# - 如何使用 Linq 在 Enumerable<T2> 中获取类 T2 成员的 IEnumerable<T1>? (C#)

标签 c# .net linq

假设我有:

 public class foobar
 {
    public int lorem;
    public int ipsum;
 }

 IEnumerable<foobar> items = new List<foobar>();
 items.add(new foobar(){lorem = 0, ipsum = 0};
 items.add(new foobar(){lorem = 1, ipsum = 1};

如何使用 Linq 获取“items”中所有“lorem”的 IEnumerable?

最佳答案

尝试以下操作

var allLorems = items.Select(x => x.lorem);

关于c# - 如何使用 Linq 在 Enumerable<T2> 中获取类 T2 成员的 IEnumerable<T1>? (C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/879394/

相关文章:

c# - 这个查询是在内存中的集合上执行的,还是在数据库中执行的?

c# - 使用 Linq to SQL 删除表中的行

c# - 安排单火事件

c# - 使用 Moq,我如何验证一个对象的所有属性都被复制了?

c# - 找不到方法 : 'Void Google.Apis.Util.Store.FileDataStore..ctor(System.String)'

c# - 从 cookie 容器向 selenium 添加 cookie

.net - 我应该在 Web API 服务与其客户端之间共享类型吗?还有哪些其他选择?

.net - 用于 .NET 的 RSS 解析器

c# - 包含 c# 和 javascript 的项目上的 Sonar runner

c# - parallel linq : AsParallel(). forAll() 使某些对象为空