IList를 구현하는 간단한 클래스를 만들려고했습니다. 그러나 DiskBackedCollection을 먼저 IList로 캐스팅하지 않으면 멤버를 사용할 수 없습니다. 어떻게 캐스팅하지 않고도 사용할 수 있습니까?IList를 구현할 때 멤버를 사용할 수 없음
public partial class DiskBackedCollection<T> : IList<T>
{
private List<T> _underlyingList = new List<T>();
int IList<T>.IndexOf(T item)
{
return _underlyingList.IndexOf(item);
}
T IList<T>.this[int index]
{
get
{
return _underlyingList[index];
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
int ICollection<T>.Count
{
get
{
return _underlyingList.Count;
}
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return new DiskBackedCollectionEnumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return new DiskBackedCollectionEnumerator(this);
}
}
[C#을 인터페이스 :
또한, 당신은 당신의 명시 적 구현을 제거해야합니다. 암시 적 구현 대 명시 적 구현] (http://stackoverflow.com/questions/143405/c-sharp-interfaces-implicit-implementation-versus-explicit-implementation). – poke
그리고 나는 그럭저럭 코드 명확성 일이었던 나의 머리에 들어갈 수 있었다! - 링크를 가져 주셔서 감사합니다. – Lee
귀하의 질문과 관련이 없지만 일반적으로 사용자 정의 기능을 위해 재정의 할 수있는 가상 메소드'InsertItem','RemoveItem' 등이있는'Collection' 기본 클래스를 사용하여 코드를 단순화합니다. –
Joe