linq列出C#中的问题

sen*_*ale 4 c# linq list linq-to-sql

我有类属性的类区域,我想添加我用linq读取此数据的数据.

List<Zones> z = new List<Zones>
z.add(new Zones(...));

var allZones = from s in db.Zones select s;
Run Code Online (Sandbox Code Playgroud)

如何将所有区域添加到z通用列表?

Dav*_*wns 5

您可以通过多种方式完成此操作:

z.AddRange(allZones);    // if there are other elements in z
z = allZones.ToList();   // if there are no other elements in z (creates a new list)
Run Code Online (Sandbox Code Playgroud)