How .NET run-time determines which member to invoke in a interface involving hiearchy
来源:互联网 发布:mysql explain括号 编辑:程序博客网 时间:2024/06/06 08:24
C# interface is very useful and powerful. The major difference in interface between C# and older languages such as java is C# introduced explicit member implementation, which can also cause considerable confusion and complexity.
In this article I want to use simplest words to hopefully cover how an actual interface implementing method is located for the invocation of a method on an instance of a class that implements some interfaces at arbitrary points in its inheritance hierarchy.
The rule for the programmer to know how it works is as simple as follows,
1. Find out what the instance actually is (the most derived class that it instantiates)
2. From this point go up until you hit a class that implements the queried interface or its descendants
3. Then class must implement the member in some way,
- First if it is explicitly implemented, this member is going to be called
- Or if it is implicitly implemented, then the member would be called, and if it's virtual/override method, it will be called as it is as such a method.
- Otherwise, it has to be implemented by its base classes, then go up and find it in the nearest base class which has exactly the same signature. Still the explicitly implemented one takes the precedence, but search through the classes stops whenever a signature match is found.
The above is also of course how the compiler looks at the code.
There should be more, but can't remember. Add later.
- How .NET run-time determines which member to invoke in a interface involving hiearchy
- How a .NET application determines what channel definition to use
- How to run a script in ubuntu?
- How to Run Successful Projects in Web Time
- How to write mutiple graphs in a run in tensorflow
- How to run a .BAT file in InstallShield?
- How to: Run Partially Trusted Code in a Sandbox
- How to: Run Partially Trusted Code in a Sandbox
- How to run a Runnable thread in Android?
- How to run a _BAT file in InstallShield
- How to Run a Program in Compatibility Mode
- How to run test cases in a specified file?
- (全英文)How to install and run a simple Asp.Net 5 Application in a Docker Container
- How to run a jar
- How To Use the C Run-Time
- how to force global variable which define in a static library to initialize?
- How to do run-time (or explicit) linking of C++ plug-in components and objects
- How to get current full screen dimention and orientation in run time
- QC七大工具
- linux awk 数组的学习心得
- 从SQL Server 2000/2005到SQL Server 2008的升级测试
- 浏览器关键时间点计算
- 范数的物理意义(转)
- How .NET run-time determines which member to invoke in a interface involving hiearchy
- 怎样开掉一名“不够好”的员工
- 黑马程序员之C#学习笔记:ADO.NET入门级材料
- POJ3185高斯消元
- Android生成一个指定大小的图片
- android中的接口和java中的接口
- 解决 Python.h:没有那个文件或目录 错误的方法
- 一只兔子的故事 花你三分钟,可能影响你一生
- 中南大学2012暑期集训中期检测训练赛-求逆元