如何从列表中仅获取特定字段
我有一个 IEnumerable 的 Lesson 对象:
IEnumerable<Lesson> filteredLessons
我通过以下方法将其转换为 List:
ToList();
但我希望返回的列表仅包含第一个属性 lessonid
,而不是所有 Lesson
代码>属性。
如何获取列表的特定属性的数据而不是对象的数据?
I have an IEnumerable of Lesson objects:
IEnumerable<Lesson> filteredLessons
I convert it to a List through the following method:
ToList();
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以先选择所需的值,如下所示:
然后您将获得 ID 列表
You can select the value you want first, like this:
And you'll get a list of ID's
如果您想使用 linq 从列表中获取特定行值,请使用以下代码:
If you want to get the the specific row value from list using linq use the following code: