C#構造函數我知道,你不能在一個接口中的構造,但這裏是我想做的事:接口
interface ISomething
{
void FillWithDataRow(DataRow)
}
class FooClass<T> where T : ISomething , new()
{
void BarMethod(DataRow row)
{
T t = new T()
t.FillWithDataRow(row);
}
}
我真的想用更換ISomething
的FillWithDataRow
方法莫名其妙的構造函數。
這樣,我的成員類可以實現接口,仍然是隻讀的(它不能用FillWithDataRow
方法)。
有沒有人有模式,會做我想要的?
你想要的成員類是隻讀的? – 2009-11-06 08:20:53
重複 - 看看這裏http://stackoverflow.com/questions/619856/interface-defining-a-constructor-signature – Blounty 2009-11-06 08:25:01
可能重複的[接口定義構造函數簽名?](https://stackoverflow.com/questions/619856 /接口限定-A-構造簽名) – Nisarg 2017-10-26 13:23:24