假设您覆盖operator*
forpoint3
和float
然后 forfloat
并且point3
您使用了这样的运算符:
point3 * float
你能知道操作符方法是否会被内联吗?
No, you can't tell for sure. In particular, because it's done at JIT time, it will depend on the version of the CLR - and I believe that the 64 bit CLR inlines differently to the 32 bit one as well. It will also depend on whether optimisations are enabled (e.g. whether you're debugging etc).
You can prevent inlining with MethodImplAttribute, but that doesn't help much...
As far as I know there is no way to know for certain as the JIT is responsible for inlining.
There is no way to know if a particular method will be inlined or not. C# itself won't ever inline a method call. Only the JITer will do this. While there are certain operations that are likely to be inlined, the JITer makes no guarantees.