我正在使用 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/