重载,覆盖和隐藏? [英] Overloading,Overriding and Hiding?

查看:204
本文介绍了重载,覆盖和隐藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下什么是重载,覆盖和隐藏在.net中?

can anyone explain what is Overloading, Overriding and Hiding in .Net?

感谢

推荐答案

重载是一个单一的方法或运营商的多个可能的签名的定义。每个签名采用不同的参数,并且基本上是一个独特的功能,比如果多种功能有不同的名字没有什么不同。这通常是用来组概念上类似的操作,如超载 + 的BigInteger 工作,并与字符串:这两个操作似乎合理的使用 + 的(除非你认为的+所有重载应该定义的Abeli​​an组 - 对字符串超载不)

Overloading is the definition of multiple possible "signatures" of a single method or operator. Each signature takes different arguments, and is essentially a distinct function, no different than if the multiple functions had different names. This is often used to group conceptually similar operations, such as overloading + to work with BigInteger and with String: both operations seem sensible to use + for (unless you think that all overloads of + should define Abelian groups -- the String overload doesn't).

重写是多个可能的的实现的同样的方法签名,定义使得实现由零参数(一般由确定的运行时类型确定名称在C#中)。

Overriding is the definition of multiple possible implementations of the same method signature, such that the implementation is determined by the runtime type of the zeroth argument (generally identified by the name this in C#).

<强>隐藏是在派生类型与相同的一个签名在其基类型之一的方法的定义中的的上位

Hiding is the definition of a method in a derived type with a signature identical to that in one of its base types without overriding.

覆盖和隐藏之间的实际差别如下:

The practical difference between overriding and hiding is as follows:

  • 如果一个方法的覆盖的,实施调用是基于参数的的运行时类型
  • 如果一个方法是简单的隐藏的,实施调用是基于的编译时间的参数类型
  • If a method is overridden, the implementation to call is based on the run-time type of the argument this.
  • If a method is simply hidden, the implementation to call is based on the compile-time type of the argument this.

这篇关于重载,覆盖和隐藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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