If you're working within the same method, you can just use a list of the anonymous type:
var jobs = new [] {
new { JobName = "Job1", JobDate = "Date1", JobUser = "User1" },
new { JobName = "Job2", JobDate = "Date2", JobUser = "User2" }
}.ToList();
var job2 = jobs.First(x => x.JobName == "Job2");
The use of the implicitly typed array allows your list to still be strongly typed, but using the anonymous type.
If you must use a List<object>
, then I'd expect:
IEnumerable<dynamic> dynamicJobs = jobs;
var job2 = dynamicJobs.First(x => x.JobName == "Job2");
to work. Note that this doesn't involve copying the list or changing the declaration type of the list at all. You could also use:
var job2 = jobs.Cast<dynamic>().First(x => x.JobName == "Job2");