谁能给我解释一下 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/