4

I have class Zones with properties and i want add data which i read with linq to this properties.

example

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

var allZones = from s in db.Zones select s;

How can i add allZones to z generic List?

6 Answers 6

5

You can do it in a number of ways:

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)
2
allZones.ForEach(x => z.Add(x));

or

z.AddRange(allZones.ToList());
2

If allZones is IEnumerable<Zones> the you can use

z.AddRange(allZones)
2
z.AddRange(allZones.ToList())
2
var z = db.Zones.ToList();

Then add any new zones to the list.

or

z.AddRange(db.Zones);
1

z=db.select(X=>X.Zones).ToList()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.