Why does this generic method require T to have a public, parameterless constructor?

前端 未结 5 770
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 01:09
public void Getrecords(ref IList iList,T dataItem) 
{ 
  iList = Populate.GetList() // GetListis defined as GetList
}

data

5条回答
  •  一生所求
    2020-12-02 01:50

    Your revised question passes in dataItem as an object of type T and then tries to use it as a type argument to GetList(). Perhaps you pass dataItem in only as a way to specify T?

    If so, the you may want something like so:

    public IList GetRecords() {
      return Populate.GetList();
    }
    

    Then you call that like so:

    IList result = GetRecords();
    

提交回复
热议问题