Вы также можете скрыть IEnumerable<int> f
из I
, указав интерфейс явно.
public class C : I
{
private List<int> list;
// Implement the interface explicitly.
IEnumerable<int> I.f
{
get { return list; }
set { list = new List<int>(value); }
}
// This hides the IEnumerable member when using C directly.
public List<int> f
{
get { return list; }
set { list = value; }
}
}
При использовании вашего класса C
виден только один f
член: IList<int> f
. Но когда вы приведете свой класс к I
, вы снова сможете получить доступ к члену IEnumerable<int> f
.
C c = new C();
List<int> list = c.f; // No casting, since C.f returns List<int>.