C# 隐式接口与显式接口

来源:互联网 发布:python字符串中\n 编辑:程序博客网 时间:2024/05/22 00:15
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 .
1 0
原创粉丝点击