转换对象的列表的对象的属性中的一个的阵列 [英] Convert a list of objects to an array of one of the object's properties

查看:75
本文介绍了转换对象的列表的对象的属性中的一个的阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有下面的类:

public class ConfigItemType
{
    public string Name { get; set; }
    public double SomeOtherThing { get; set; }
}



然后我提出以下类的列表(列表< ConfigItemType> MYLIST

现在我有下面签名的方法:

Now I have a method with the following signature:

void AggregateValues(string someUnrelatedValue, params string[] listGoesHere)

我如何能适应 MYLIST listGoesHere 使用价值ConfigItemType.Name 作为PARAMS字符串数组?

How can I fit MyList in to the listGoesHere using the value in ConfigItemType.Name as the params string array?

我相当肯定LINQ的可以做到这一点....但 MYLIST 不具有选择它方法(这是我会用)。

I am fairly sure that Linq can do this.... but MyList does not have a select method on it (which is what I would have used).

推荐答案

您正在寻找

MyList.Select(x=>x.Name).ToArray();



由于选择是一个扩展方法确保通过增加一个

Since Select is an Extension method make sure to add that namespace by adding a

使用System.Linq的

到您的文件 - 那么它会显示与智能感知

to your file - then it will show up with Intellisense.

这篇关于转换对象的列表的对象的属性中的一个的阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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