2013-06-03 5 views
3

내가 사용하고있는 라이브러리에서 이런 종류의 정의를 보았습니다. 나는 TObjectType : CSObject가 어디 있는지에 대해서 미쳤다. 그것이 작동하고 컴파일되기 때문에 제약 조건에서 같은 시간을 사용할 수있는 것처럼 보입니다.하지만 이것이 실제로 의미하는 바는 무엇입니까?클래스 정의에 같은 유형 사용하기

public class CSList<TObjectType>: CSList, IList<TObjectType>, IList 
    where TObjectType: CSObject<TObjectType> 

답변

5

그것은 여기 TObjectTypeCSList<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; } 
} 

는 파생 클래스를 선언
관련 문제