私が使用しているライブラリでこの種の定義を見たことがあります。where TObjectType: CSObject に夢中になりました。動作してコンパイルされるため、制約で同じ時間を使用できるように見えることは明らかですが、これは実際にはどういう意味ですか?
public class CSList<TObjectType>: CSList, IList<TObjectType>, IList
where TObjectType: CSObject<TObjectType>
これは、TObjectType
here が から継承する必要があることを意味しCSList<TObjectType>
ます。
通常、このコンストラクトを使用して、使用する実際の派生クラスに合わせて調整される基本クラスの型指定されたメソッドとプロパティを取得します。
このような派生クラスを宣言するには:
public class SomeDerivedClass : CSList<SomeDerivedClass>
例:
public class Base<T>
{
public T[] Values { get; set; }
}
public TestCollection : Base<TestCollection>
{
// here, Values inherited from Base will be:
// public TestCollection[] Values { get; set; }
}
public OtherCollection : Base<OtherCollection>
{
// here, Values inherited from Base will be:
// public OtherCollection[] Values { get; set; }
}