List of Generic Lists
I would like to create a list of objects in which there is a generic list.
So what I have is this object:
public class agieDBColumn<dataTp> where dataTp:IComparable{
private string _header;
private string _longHeaderName;
private List<dataTp> _data;
public string header {
get { return _header; }
set { _header = value; }
}
public string longHeaderName {
get { return _lon开发者_如何学编程gHeaderName; }
set { _longHeaderName = value; }
}
public List<dataTp> data {
get { return _data; }
set { _data = value; }
}
}
And this is how I would like to use it:
List<DBColumn> columns;
Then I would like to add new instances to the list "columns" specifying the type.
There does not seem to be a syntaxs that allows this though as I get "Error 1 Using the generic type Picker.DBColumn<dataTp>
requires 1
type arguments Frm.cs 56 9 FCAgieStratPicker
" when trying to define the type of List I would like.
Is this even possible? Or would I need to use the base class object in this case?
Maybe there is a better way to handle the data I would like to represent in memory.
It seems what you eventually want to achieve is already provided by the System.Data.DataTable
class.
Adding columns:
DataTable dataTable = new DataTable();
DataColumn column = dataTable.Columns.Add(header, type);
column.Caption = longHeaderName;
Adding rows:
dataTable.Rows.Add(someIntValue, someStringValue, ...)
Your type is generic. If you want to create a list of that type you'll need to specify the type for your class as well.
List<agieDBColumn<int>> columns = ...
精彩评论