Declaring an implicitly typed variable inside conditional scope and using it outside
In the simplified code below, if(city == "New York City") { var MyObject = from x in MyEFTable where x.CostOfLiving == "VERY HIGH" select x.*; } else { var MyObject = from x in MyEFTable where x.CostOfLiving == "MODERATE" select x.*; } foreach (var item in MyObject) { Console.WriteLine("<item's details>"); } The variable MyObject is not accessible outside conditional block. How can I iterate outside the if..else ? Let's clarify your confusing question. The problem is that you have two local variables, each of which has the same "unspeakable" type -- a sequence of anonymous type. I would change