我有一个匿名对象列表:
var jobs = new List<object>
{
new
{
JobName = "Job1",
JobDate = "Date1",
JobUser = "User1"
},
new
{
JobName = "Job2",
JobDate = "Date2",
JobUser = "User2"
}
};
如何使用 linq 找到“Job2”?
例如
var job2 = jobs.Where(x=>x.JobName == "Job2");
我知道以下内容,但无法以优雅的方式将其应用于上面的用例:
var anonymJob = new
{
JobName = "Job2",
JobDate = "Date2",
JobUser = "User2"
};
dynamic tJob = anonymJob.GetType();
string jobName = tJob.JobName; // this will be "Job2"
请注意 jobs.First() 或 Last() 不被接受,因为这个问题的正确答案是如何根据其特定属性找到工作。
谢谢