How can I create an empty collection from an anonymous collection most elegantly in C#?
Posted
by NetMage
on Stack Overflow
See other posts from Stack Overflow
or by NetMage
Published on 2010-05-20T22:46:52Z
Indexed on
2010/05/20
22:50 UTC
Read the original article
Hit count: 134
If I have an anonymous type created by LINQ
var ans = from r in someList where someCondition(r) select new { r.a, r.b };
What is the best way to create an empty matching collection so I can move elements to the new collection:
var newans = ?
foreach (r in ans) { if (complicated(r) newans.Add(r); }
Is there some way to use Enumerable.Empty<>()?
© Stack Overflow or respective owner