c# - query a list of dynamic objects for a FirstOrDefault -



c# - query a list of dynamic objects for a FirstOrDefault -

the next code homecoming enumerable of dynamic objects.

protected override dynamic get(int id) { func<dynamic, bool> check = x => x.id == id; homecoming enumerable.where<dynamic>(this.get(), check); }

how select firstordefault single object not enumerable?

similar this answer want singleordefault.

simplest way probably

protected override dynamic get(int id) { homecoming get().firstordefault(x=>x.id==id); }

since people have had problem making work, test new .net 4.0 console project (if convert 3.5 need add together system.core , microsoft.csharp references) , paste program.cs. compiles , runs without problem on 3 machines i've tested on.

using system; using system.collections.generic; using system.linq; using system.dynamic; namespace consoleapplication1 { internal class programme { protected dynamic get2(int id) { func<dynamic, bool> check = x => x.id == id; homecoming enumerable.firstordefault<dynamic>(this.get(), check); } protected dynamic get(int id) { homecoming get().firstordefault(x => x.id == id); } internal ienumerable<dynamic> get() { dynamic = new expandoobject(); a.id = 1; dynamic b = new expandoobject(); b.id = 2; dynamic c = new expandoobject(); c.id = 3; homecoming new[] { a, b, c }; } static void main(string[] args) { var programme = new program(); console.writeline(program.get(2).id); console.writeline(program.get2(2).id); } } }

c# linq dynamic .net-4.0 lambda

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -