不应该算是私有的,应该叫做显示实现接口
因为二者都有 Count ,为了区别它的实现方式就变成这样了string[] ar = new string[5];
IList il = ar as IList;
il.Add();
因为二者都有 Count ,为了区别它的实现方式就变成这样了string[] ar = new string[5];
IList il = ar as IList;
il.Add();
调试欢乐多
arr.Count.ToString(); // 不能编译IList list = arr as IList;
list.Count.Tostring(); // 恭喜你能编译了
这算不算接口多态?
public abstract class Array
我看了,就ICollection接口声明了Count属性.IList接口中声明了Add(..)方法。Aarry虚拟类、IList接口和ICollection接口没有再声明其他Add(..)和Count了。请指教!
string[] arr = new string[5];
Console.Write(arr.Count());
编译没有任何问题..
string[] arr = new string[5];
Console.WriteLine( arr.Count());
IList list = arr as IList;
Console.WriteLine(list.Count);
编译也没任何问题只是arr.Count()是一个方法 不是属性.. 我用的VS2008
第一个程序不可能编译通过的。Array中根本就没Count()方法。
Console.Write(arr.Count());
这个在VS2008里面编译是没有任何问题的
这个COUNT()方法是个扩展方法(.NET3.5新特性)
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.chs/dv_fxdesignguide/html/e3766a81-fbe6-4358-8e9e-9424a892dd79.htm
注意其中一段文字如下:
当接口成员由类显式实现时,只能通过使用对接口的引用来访问该成员。这将导致隐藏接口成员。