Using List in C# (Generics)

前端 未结 4 436
灰色年华
灰色年华 2021-02-03 22:25

That\'s a pretty elementary question, but I have never delved into generics before and I found myself in the need to use it. Unfortunately I don\'t have the time right now to go

4条回答
  •  攒了一身酷
    2021-02-03 22:33

    You need to let c# know what type is sent:

    List list1 = getListType1();
    List list2 = getListType2();
    
    if (someCondition)
        MyMethod(list1);
    else
        MyMethod(list2);
    
    void MyMethod(List list){
        //Do stuff
    }
    

提交回复
热议问题