Anonymous type collections?

前端 未结 7 1201
醉梦人生
醉梦人生 2021-01-05 02:47

I am looking for best practices for creating collections made from anonymous types.

There are several approaches - this one and most answers on this thread assume th

7条回答
  •  星月不相逢
    2021-01-05 03:31

    For a very different answer... LINQ?

    In my case, I am iterating over a collection - for each item in the collection I would like to collect related objects in an anonymous type (acting as a tuple). I need these anonymous types to be put in a collection and then sort them for further work.

    That sounds like:

    var list = (from item in collection
              from related in item.Relationship
              order by ...something...
              select new {item,related}).ToList()
    

提交回复
热议问题