繁体   English   中英

如何在Xamarin-C#-ios中将通用类型列表作为参数传递给TableSource的构造函数?

[英]How to pass a generic type list as parameter to a constructor of TableSource in xamarin-C#-ios?

我正在使用UITableViewSource的子类在xamarin ios的UITableView中填充数据。 我想将List<T> someList作为参数传递给类的构造函数。 在搜索时,我遇到了将此参数传递给模板类型的C#通用new()的方法 ,但这无济于事。 我怎样才能实现这样的目标

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


}

这完全可行吗?

这将允许您将通用列表类型传递给构造函数

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();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM