LINQ gems: Troubles with Out Parameters
How do you deal with out parameters inside of LINQ queries?
Almost every time I come across the need to invoke a method inside of a LINQ query, which uses an out argument, I need to stop for a moment and think about what the correct solution is. And ...
mydevtricks.com8 min read
Hi Jan, I really appreciate your linq gems! This one pointed me to another solution that, I hope, you and your blog readers could like. It is similar to the value tuple you mentioned:
Using the
newkeyword to create an anonymous type in aletclause:var query = from word in testWords let entry = new { word, usage = wordUsage.TryGetValue(word, out var u) ? u : 0, } orderby entry.usage select (entry.word, entry.usage);Or maybe you can directly do:
//[...] select entry;to use the whole anonymous object as a result.