我定義兩個接口如下:訪問成員
public interface IData
{
double value { set; get; }
}
public interface IInterval<C, M>
{
C left { set; get; }
M data { set; get; }
}
然後,我使用這兩個接口,用於以下類聲明。
public class TESTClass<I, M>
where I : IInterval<int, M>, new()
where M : IData
{
public I interval{ set; get; }
public TESTClass()
{
// This is invalid, cos property value is not visible at initialization ...
interval = new I() { left = 0, data.value = 0 };
// instead I have to do as:
interval = new I() { left = 0 };
interval.data.value = 0;
}
}
我在這裏錯過了什麼? 如果你能幫我弄清楚這一點,我將不勝感激。
你爲什麼不在'IInterval'處添加'where M:IData'? –
ja72
2014-08-27 16:28:48