別のクラスの特定のクラスのテンプレートを使用できますか?C#外部クラスのテンプレートタイプを使用
例:
class DBObject<DataType>
{
private string _name;
private DataType _value;
public DBObject()
{
_name = String.Empty;
}
public DBObject(string name)
{
this._name = name;
}
public DataType GetValue
{
get { return _value; }
set { _value = value; }
}
}
DataType
は、私は私のTestTbl
クラスDBObject<DataType>
要素を含むクラスにDBObject
を使用していますテンプレートです。
class TestTbl : DBTableObjects
{
public DBObject<int> _id;
DBObject<string> _name;
DBObject<string> _address;
TestTbl()
{
AddDBTableObject(_id = new DBObject<int>("id"));
}
}
AddDBTableObject
機能はDBTableObjects
クラスにList
に要素を追加します。
class DBTableObjects
{
List<DBObject> ls;
public DBTableObjects()
{
ls = new List<DBObject>();
}
protected void AddDBTableObject(DBObject obj)
{
ls.Add(obj);
}
}
問題:List<DBObject>
もDBObject
例えばtemplatetypeが必要です。ここでDBObject
クラスのDataType
を使用するにはどうすればよいですか?
DBTableObjectsを使用しないのはなぜ? –
CodeNotFound