How to Casting DataSource to List?

后端 未结 4 1501
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 11:11

I have the following method that load products on a DataGridView

private void LoadProducts(List products)
{
    Source.DataSource = products;          


        
4条回答
  •  暖寄归人
    2021-01-17 11:26

    You can't cast covariantly directly to List;

    Either:

    List products = (List)Source.DataSource;
    

    or:

    List products = ((List)Source.DataSource).Cast().ToList();
    
        

    提交回复
    热议问题