Cast IList to List

后端 未结 9 1676
时光取名叫无心
时光取名叫无心 2020-12-08 06:09

I am trying to cast IList type to List type but I am getting error every time.

List subProducts= Model.subproduct         


        
相关标签:
9条回答
  • 2020-12-08 06:52

    If you have an IList containing interfaces, you can cast it like this:

    List to IList

    List<Foo> Foos = new List<Foo>(); 
    IList<IFoo> IFoos = Foos.ToList<IFoo>();
    

    IList to List

    IList<IFoo> IFoos = new List<IFoo>();
    List<Foo> Foos = new List<Foo>(IFoos.Select(x => (Foo)x));
    

    This assumes Foo has IFoo interfaced.

    0 讨论(0)
  • 2020-12-08 06:53
        public async Task<List<TimeAndAttendanceShift>> FindEntitiesByExpression(Expression<Func<TimeAndAttendanceShift, bool>> predicate)
        {
            IList<TimeAndAttendanceShift> result = await _dbContext.Set<TimeAndAttendanceShift>().Where(predicate).ToListAsync<TimeAndAttendanceShift>();
    
            return result.ToList<TimeAndAttendanceShift>();
        }
    
    0 讨论(0)
  • 2020-12-08 06:54
    List<ProjectResources> list = new List<ProjectResources>();        
    IList<ProjectResources> obj = `Your Data Will Be Here`;
    list = obj.ToList<ProjectResources>();
    

    This Would Convert IList Object to List Object.

    0 讨论(0)
提交回复
热议问题