2
DB.DBEntities ent = new DB.DBEntities();

foreach (var brn in ent.Sites.ToList()) 
{
     //Do work                 
}

If I try above code, it gives Unreachable code on var branch

But if I store the list in another list object and iterate on it, no warning is given.(As below)

DB.DBEntities ent = new DB.DBEntities();
List<DB.Site> list = ent.Sites.ToList();

foreach (var brn in list) 
{
     //Do work                 
}

Can some one please explain why does this happen?

3

0

Your Answer

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

Browse other questions tagged or ask your own question.