2014-10-30 89 views
0

我正在使用UITableViewSource的子類來填充Xamarin ios中的UITableView中的數據。我想將List<T> someList作爲參數傳遞給類的構造函數。雖然搜索我遇到了這Passing arguments to C# generic new() of templated type,但它並沒有幫助我的原因。我怎麼能達到這樣的事情如何將泛型類型列表作爲參數傳遞給xamarin-C#-ios中TableSource的構造函數?

public class TableSource : UITableViewSource 
{ 
    public TableSource(List<T> list) where T : new(){ 
    } 


} 

這是可以做到的嗎?

回答

1

,讓你通過一個通用的列表類型構造

public class TableSource<T> : UITableViewSource where T : new() 
{ 
    public TableSource(List<T> list) 
    { 

    } 


    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
    { 
     throw new NotImplementedException(); 
    } 

    public override int RowsInSection(UITableView tableview, int section) 
    { 
     throw new NotImplementedException(); 
    } 
} 
相關問題