gpt4 book ai didi

c# - 如果我不实现分部方法会怎样?

转载 作者:太空宇宙 更新时间:2023-11-03 20:12:29 24 4
gpt4 key购买 nike

我使用 SQLMetal 生成了一些代码并使用了一段时间。刚才看了生成的代码,在每个类中喜欢了几个部分函数,​​这些函数我没有实现过,也没有被SQLMetal实现过。这些函数在代码中被调用。我想知道 - 当我调用这样一个不存在的函数时发生了什么?

最佳答案

These functions were called in the code. I wonder - whats happening when I call a function like that - that doesn't exist?

该调用已被编译器完全删除。为了调用该方法而评估的任何表达式也被删除 - 所以如果你有这个:

SomePartialMethod(ComputeSomeValue());

SomePartialMethod没有实现,ComputeSomeValue不会被调用。

或作为 MSDN puts it :

If the method is not implemented, then the compiler removes the method signature and all calls to the method. The calls to the method, including any results that would occur from evaluation of arguments in the calls, have no effect at run time. Therefore, any code in the partial class can freely use a partial method, even if the implementation is not supplied. No compile-time or run-time errors will result if the method is called but not implemented.

关于c# - 如果我不实现分部方法会怎样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19098585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com