我有一个类:
public class EventsList
{
public int Id { get; set; }
public string Title { get; set; }
}
并列出我收集了一些对象的地方:
List<EventsList> CultureEvents { get; set; }
如何从列表中创建新的字符串列表或从列表中获取所有对象标题?
答案 0 :(得分:5)
var result = CultureEvents.Select(x=>x.Title).ToList()
答案 1 :(得分:0)
using System.Linq; // this is usually at the top already
var result = from e in CultureEvents
select e.Title
答案 2 :(得分:0)
List<string> TitleList = new List<string>();
foreach(var title in CultureEvents)
{
TitleList.Add(title.Title);
}