3 ms·
Interestingly, while the C# language uses static dispatch by default, it is at least the case that Microsoft's compiler always emits the `callvirt` instruction[
by noblethrasher 10y ago
Interestingly, while the C# language uses static dispatch by default, it is at least the case that Microsoft's compiler always emits the `callvirt` instruction[1]. This is because the language spec requires that a method call to a null instance of a reference type must throw a NullReferenceException, and callvirt is apparently the cheapest way to do that on the CLR.
[1] https://blogs.msdn.microsoft.com/ericgu/2008/07/02/why-does-c-always-use-callvirt/ https://blogs.msdn.microsoft.com/ericgu/2008/07/02/why-does-...
[2] §6.1 of the C# language spec.