C# 隱式介面與顯式介面

mybwu_com發表於2014-03-28
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 .

相關文章