Declaring an implicitly typed variable inside conditional scope and using it outside

前端 未结 7 2115
闹比i
闹比i 2021-01-06 01:51

In the simplified code below,

if(city == \"New York City\")
{
  var MyObject = from x in MyEFTable
                     where x.CostOfLiving == \"VERY HIGH\         


        
相关标签:
7条回答
  • 2021-01-06 02:20
    List<MyObject> list = null; 
    
    if(city == "New York City")    
       list = (from x in MyEFTable  where x.CostOfLiving == "VERY HIGH"
                         select x.*).ToList();       
    else    
       list = (from x in MyEFTable where x.CostOfLiving == "MODERATE"
                         select x.*).ToList();        
    
    foreach (var item in list)   
         Console.WriteLine("<item's details>");    
    
    0 讨论(0)
提交回复
热议问题