我知道一个接口没有方法实现,但是compareto(IComparable成员))如何具有排序功能和MoveNext(IEnumerator成员)可以移动指针位置? [英] I know an interface doesn't have method implementation, but how do compareto (IComparable member)) can have sorting functionality and MoveNext(IEnumerator member) can move pointer position ?

查看:126
本文介绍了我知道一个接口没有方法实现,但是compareto(IComparable成员))如何具有排序功能和MoveNext(IEnumerator成员)可以移动指针位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人可以解释..

推荐答案

正如Wes所说,实现接口的类通过CompareTo提供功能方法和MoveNext接口方法作为接口合同的一部分。



但还有一点涉及。接口不执行实际的排序操作:它由扩展方法执行,扩展方法声明为使用实现IComparable接口的集合,而不是接口本身。与MoveNext类似,它不是从IEnumerable接口调用,而是从使用IEnumerable集合作为参数的索引器和foreach方法调用。
As Wes has said, the class which implements the interface provides the functionality via the CompareTo method and MoveNext interface methods as part of the Interface contract.

But there is a little more than that involved. The actual sorting operation is not performed by the Interface: it is performed by extension methods which are declared to use a collection which implements the IComparable interface, rather than by the interface itself. Similarly with MoveNext, it is not called from the IEnumerable Interface, but from indexers and foreach methods which use IEnumerable collections as their parameters.


这篇关于我知道一个接口没有方法实现,但是compareto(IComparable成员))如何具有排序功能和MoveNext(IEnumerator成员)可以移动指针位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆