本文介绍了为什么需要超载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基类中,我有以下2个声明:


Overridable Sub Remove(ByVal wIndex As Integer)




Overridable Sub删除(ByVal wValue As Object)


在一个直接派生的类中,我有以下声明:


重载覆盖Sub删除(ByVal wIndex as Integer)


为什么派生类需要重载?如果没有它,intellisense告诉我

"在基类中删除阴影是一个可重载的方法。如果你想要基本方法重载这个方法,那么必须将此方法声明为Overloads?"由于两种方法的

签名是相同的,我认为编译器可以确定派生方法是否覆盖了Remove(Integer)vs

删除(对象)。我错过了什么?


根据intellisense消息推断,如果删除

在基础cass中没有超载我是否准确派生的那个不需要Overloads吗?


-

// Lee Silver

// Information Concepts Inc 。

//


促进自动将数据转换为信息

自1982年以来

In a base class I have the following 2 declarations:

Overridable Sub Remove(ByVal wIndex As Integer)
and

Overridable Sub Remove(ByVal wValue As Object)

In an immediately derived class I have the following declaration:

Overloads Overrides Sub Remove(ByVal wIndex As Integer)

Why is Overloads needed in the derived class? Without it intellisense tells me
"Remove shadows an overloadable method in the base class. If you want to
overload the base method this method must be declared Overloads?" Since the
signatures of the 2 methods are the same, I would think the compiler could
determine that the derived method is overriding the Remove(Integer) vs
Remove(Object). What am I missing?

Is it accurate to deduce, based on the intellisense message, that if Remove
weren''t overloaded in the base cass I wouldn''t need Overloads in the derived one?

--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com

Facilitating the automated conversion of Data into Information
since 1982

推荐答案





这不是编译器,而是读取代码的人。更多

信息可以通过将插入符号设置为''Overloads''并按

F1键来找到。


- -

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>



It''s not for the compiler, it''s for the person who reads the code. More
info can be found by setting the caret onto ''Overloads'' and pressing the
F1 key.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>





我之前有过F1' '重载超载,解释并没有帮助我:)。我认为Overbides''会告诉读者代码中有一个在父类中具有相同命名/签名功能的



从''about Overloads关键字''引用:" Overloads关键字声明一个

属性或方法,其名称与现有成员相同,但带有

参数列表与原始成员不同。我不认为这适用于

,因为这些方法具有相同的参数列表(除非编译器以某种方式

不能告诉哪个方法被覆盖)。 br />

因此我认为这一段适用:Overloads也可用于

影子现有成员或一组重载成员基类。当您以这种方式使用Overloads时,使用相同的

名称和与基类成员相同的参数列表声明属性或方法,并且您不提供

Shadows关键字。


从这看起来,我不需要在基类中使用Overridable和

覆盖派生类 - 只是派生类中的Shadows。那么为什么

有Overrideable和Overrides如果我还需要Overloads?我错过了什么,

但我不知道是什么;因为对我来说,Overriding与Shadowing不一样

(前者有相同的论点而后者不相同)。

-

// Lee Silver

// Information Concepts Inc.

//

促进数据自动转换为信息

自1982年以来



I had previously F1''d on Overloads, and the explanation didn''t help me :). I
would think that the Overrides'' would tell the reader of the code that there is
an identically named/signed function in the parent class.

Quoting from the ''about Overloads keyword'': "The Overloads keyword declares a
property or method with the same name as an existing member, but with an
argument list different from the original member." I don''t think this applies
because the methods have the same argument list (unless the compiler somehow
can''t tell which method is being overridden).

Therefore I''m thinking this paragraph applies: "Overloads can also be used to
shadow an existing member, or set of overloaded members, in a base class. When
you use Overloads in this way, you declare the property or method with the same
name and the same argument list as the base class member, and you do not supply
the Shadows keyword."

It would seem from this that I don''t need Overridable in the base class and
Overrides in the derived class -- just Shadows in the derived class. Then why
have Overridable and Overrides if I also need Overloads? I''m missing something,
but I don''t know what; because to me, Overriding isn''t the same as Shadowing
(the former has identical arguments and the latter doesn''t).
--
// Lee Silver
// Information Concepts Inc.
// http://www.information-concepts.com

Facilitating the automated conversion of Data into Information
since 1982


这篇关于为什么需要超载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-09 06:41