开发者

What is Run Time and Compile Time Polymorphism?

Can anyone explain to me run-time polymorphism and compile time polymorphism with respect to C#?

I have found si开发者_如何学JAVAmilar questions on SO but they were regarding C++.


Here is a site with a good explanation:

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

To quote the article:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜