C# 隐式接口与显式接口

Interface :


IList.CopyTo 


class myClass:IList{
}





Implicit Implementation :




class myClass:IList{
public void CopyTo(Array array, int index)
{
    throw new NotImplementedException();
}


}






Explicit Implementation :


class myClass:IList{
void ICollection.CopyTo(Array array, int index)
{
    throw new NotImplementedException();
}


}




Invoke :
myclass.CopyTo //invalid with explicit
((IList)myClass).CopyTo //valid with explicit.






Explicit Only be accessed when the instance is casted to interface type .
implicit can be accessed by class type(implemented interface) and interface type .

你可能感兴趣的:(C# 隐式接口与显式接口)