C# 合并对象列表中的路径

C# 合并对象列表中的路径,c#,visual-studio,ienumerable,C#,Visual Studio,Ienumerable,我有一个IEnumerable对象,我想从所有Name属性创建一个路径。 我做到了: 而项是IEnumerable 我怎样才能比foreach做得更好 Path.Combine()可以使用数组,但我需要隔离Name属性。您可以使用LINQ: Path.Combine(items.Select(o => o.Name)) foreach有什么问题?请详细说明。我只是认为有一种更好的方式使用LinqLINQ,它肯定更可读,更易于编写。请注意性能方面的影响。“与'System.IO.Path.

我有一个
IEnumerable
对象,我想从所有
Name
属性创建一个路径。
我做到了:

IEnumerable

我怎样才能比foreach做得更好

Path.Combine()
可以使用数组,但我需要隔离
Name
属性。

您可以使用LINQ:

Path.Combine(items.Select(o => o.Name))

foreach有什么问题?请详细说明。我只是认为有一种更好的方式使用LinqLINQ,它肯定更可读,更易于编写。请注意性能方面的影响。“与'System.IO.Path.Combine(params string[])匹配的最佳重载方法有一些无效的参数可能该参数需要一个
ToArray
结尾:
Path.Combine(items.Select(o=>o.Name.ToArray())
谢谢@SinaIravanian:)
[JsonObject(MemberSerialization.OptIn)]
public class SomeClass
{
    [JsonProperty(PropertyName = "type")]
    public string Type { get; internal set; }

    [JsonProperty(PropertyName = "id")]
    public string Id { get; internal set; }

    [JsonProperty(PropertyName = "name")]
    public string Name { get; internal set; }
}  
Path.Combine(items.Select(o => o.Name))