【发布时间】:2016-04-01 21:46:50
【问题描述】:
假设我有这样的对象:
public class Car
{
public string Name { get; set; }
}
public class MyCars
{
public List<Car> Cars{ get; set; }
public string GetCars
{
get
{
return this.Cars != null ? string.Join(", ", Cars.Select(x => x.Name)) : "N/A";
}
}
}
如果我的列表中有 3 辆汽车的名称属性设置为“Honda”、“VW”、“GMC”
如何将该列表转换为字符串,以将列表中每辆车的名称显示为逗号分隔: 本田、大众、GMC
我试图在我的 XAML 中将其链接为:
<TextBlock Name="txtCarNames" Text="{Binding Path=MyCars.GetCars}"/>
【问题讨论】:
标签: c#