“过载"是指VB.NET中的关键字 [英] "Overloads" keyword in VB.NET

查看:67
本文介绍了“过载"是指VB.NET中的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您真的需要此关键字来重载方法吗?使用重载关键字与仅具有不同的方法签名之间有什么区别?

Do you really need this keyword to overload methods? What is the difference between using the overloads keyword vs. just having different method signatures?

推荐答案

在同一类中,Overloads关键字是可选的,但是如果将一个方法声明为OverloadsOverrides,则必须对所有方法都使用它该方法的重载.

Within the same class, the Overloads keyword is optional, but if one method is declared Overloads or Overrides, you must use it for all overloads of that method.

' this is okay
Sub F1(s as String)
Sub F1(n as Integer)

' This is also okay
Overloads Sub F2(s as String)
Overloads Sub F2(n as Integer)

' Error
Overloads Sub F3(s as String)
Sub F3(n as Integer)

但是,当您在派生类中重载基类方法时,情况将变得更加复杂.

It gets more complicated when you are overloading base class methods in a derived class however.

如果基类具有多个重载方法,并且您想在派生类中添加一个重载方法,则必须使用Overloads关键字标记派生类中的方法,否则基类中的所有重载方法在派生类中不可用.

If a base class has several overloaded methods and you want to add an overloaded method in a derived class, then you must mark the method in the derived class with the Overloads keyword, otherwise all the overloaded methods in the base class are unavailable in the derived class.

有关更多详细信息,请参见 MSDN .

See MSDN for more details.

这篇关于“过载"是指VB.NET中的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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