获取所有数组列表中的属性值c#

时间:2014-08-06 10:37:46

标签: c# arrays linq windows-phone-7

如何获取数组列表中属性的值?我尝试了以下代码,但我得到像System.Linq.Enumerable这样的东西。我需要在该数组的所有列表中获取属性的值。

sampleClass.Add(new ClassProp()
        {
            NameAttributes = listDetails.Select(x=>x.FirstName).ToString()

        });

listDetails是arry列表的列表。 NameAttributes是字符串属性。

2 个答案:

答案 0 :(得分:2)

使用string.Join

NameAttributes = string.Join("," ,listDetails.Select(x=>x.FirstName));

答案 1 :(得分:0)

假设NameAttributes是例如IEnumerable<string>然后

sampleClass.Add(new ClassProp()
  {
    NameAttributes = (from MyClass x in arrayList select x.MyProperty).ToList()
  });