c# - 如何将泛型类型列表作为参数传递给 xamarin-C#-ios 中 TableSource 的构造函数?

标签 c# ios uitableview generics xamarin

我正在使用 UITableViewSource 的子类来填充 xamarin ios 中 UITableView 中的数据。我想通过 List<T> someList作为类的构造函数的参数。在搜索时我遇到了这个 Passing arguments to C# generic new() of templated type ,但这对我的事业没有帮助。我怎样才能实现这样的目标

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

关于c# - 如何将泛型类型列表作为参数传递给 xamarin-C#-ios 中 TableSource 的构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26645880/

相关文章:

c# - 当使用TryUpdateModel绑定(bind)时,MVC ValidationSummary会忽略模型级别的验证错误

objective-c - ipad编程指导

c# - 两个泛型类型之间的转换失败

c# - 获取解决方案中的所有启动项目

ios - 在移动 safari `position:fixed` 上覆盖 `platform=ios` 卡在 <ion-header> 后面

ios - 单击TableViewCell时如何将数据从NSObject传递到另一个ViewController?

ios - 我正在显示诸如 Expendable Tableview 之类的数据

ios - Swift cellForRowAtIndexPath 定义与先前的值冲突

c# - 通过运算符对 Lambda 表达式进行分组并将它们与 DapperExtensions 的 PredicateGroups 一起使用

ios - 通过代码加载 Storyboard场景