How to add an item in a collection using Linq and C#

后端 未结 2 1657
借酒劲吻你
借酒劲吻你 2021-02-20 02:37

I have a collection of objects. e.g.

List subscription = new List
{
    new Subscription{ Type = \"Trial\", Type = \"Offl         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-20 03:16

    I would suggest using List.Add():

    subscription.Add(new Subscriptioin(...))
    

    LINQ Union() overkill by wrapping a single item by a List<> instance:

    subscriptions.Union(new List { new Subscriptioin(...) };
    

提交回复
热议问题