局部方法为什么必须是无效的? [英] Why do partial methods have to be void?

查看:98
本文介绍了局部方法为什么必须是无效的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在学习C#与所谓的开始的Visual C#2010这本书,我是讨论了不同方面和部分方法和类特征的节。

I am currently learning C# with the book called Beginning Visual C# 2010 and I am in the chapter that discusses different aspects and characteristics of partial methods and classes.

要报价书:

考虑在这一点上,为什么分部方法不能有返回类型。如果你能回答你的
自己满意,你可以肯定你完全理解这个问题 - 这样就留下作为一个练习你

Consider at this point why partial methods can’t have a return type. If you can answer that to your own satisfaction, you can be sure that you fully understand this topic — so that is left as an exercise for you."

这是我卡住。
,我能想到的唯一原因是,当该方法的返回值分配给东西的代码,它会产生,如果错误出现不为偏方法来实现的定义。

This is where I get stuck. The only reason that I can think of is that when the method's return value is assigned to something in the code, it would generate an error if there is no definition implemented for the partial method.

有人能清除这个话题我好吗?

Can someone clear this topic for me please?

推荐答案

由于他们的呼叫不能被从调用代码的情况下,消除了它们没有不破坏它实施

Because calls to them can't be eliminated from the calling code in case they are not implemented without breaking it.

实施例

partial void foo();
partial int bar();

调用代码:

...
foo(); // successfully removed if foo isn't implemented
int x = bar() * 2; // what to do here?
Console.WriteLine(x);

这篇关于局部方法为什么必须是无效的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆