如何仅从列表中获取特定字段 [英] How to get only specific field from the list

查看:47
本文介绍了如何仅从列表中获取特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IEnumerable的Lesson对象:

I have an IEnumerable of Lesson objects:

IEnumerable<Lesson> filteredLessons

我通过以下方法将其转换为列表:

I convert it to a List through the following method:

ToList();

但是我希望返回的列表仅包含第一个属性 lessonid ,而不是所有的 Lesson 属性.

But I want the returned list to contain only the first property, lessonid, not all the Lesson properties.

如何获取列表中特定属性的数据而不是对象?

How can I get the data of specific property of the list instead of the objects?

推荐答案

您可以先选择所需的值,如下所示:

You can select the value you want first, like this:

filteredLessons.Select(l => l.lessonId).ToList();

您将获得ID的列表

这篇关于如何仅从列表中获取特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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