c# - 什么是运行时和编译时多态性?

标签 c# oop polymorphism

谁能给我解释一下 C# 的运行时多态性和编译时多态性?

我在 SO 上发现了类似的问题,但它们是关于 C++ 的。

最佳答案

这是一个有很好解释的网站:

http://www.dickbaldwin.com/csharp/Cs000120.htm

引用文章:

The reason that this type of polymorphism is often referred to as runtime polymorphism is because the decision as to which version of the method to execute cannot be made until runtime. The decision cannot be made at compile time (as is the case with overloaded methods).

The decision cannot be made at compile time because the compiler has no way of knowing (when the program is compiled) the actual type of the object whose reference will be stored in the reference variable.

In an extreme case, for example, the object might be obtained at runtime from a network connection of which the compiler has no knowledge.

关于c# - 什么是运行时和编译时多态性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6163998/

相关文章:

c# - C#中MySql命令 "load data infile"执行错误

c# - 在 C# 中更改列表值也会更改您的复制元素

C++ 静态工厂方法与构造函数 : how to avoid copying?

C++ 多态性 : Derived class calls Base class virtual funciton instead of the overriden derived one

c# - 永久设置下拉列表的值

c# - 开始使用 Orleans : Implementation, 托管和部署

algorithm - 多级遍历的数据结构

java - 修改匿名类中的外部类属性

c++ - C++中堆类的多态性

C++ 多态性和 vector ,将 vector 的派生类指向 vector 的基类