如何返回从C#分部方法的价值? [英] How to return value from C# partial method?
本文介绍了如何返回从C#分部方法的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法这样做,因为它似乎分部方法必须返回void(我真不明白这个限制,但让它)?
Is there a way to do so as it seems partial method must return void (I really don't understand this limitation but let it be) ?
推荐答案
那么,在技术上你的可以的回报,从一个局部的方法的价值,但它必须是通过 REF
的说法,所以这是相当尴尬的:
Well, technically you can "return" a value from a partial method, but it has to be through a ref
argument, so it's quite awkward:
partial void Foo(ref int result);
partial void Foo(ref int result)
{
result = 42;
}
public void Test()
{
int i = 0;
Foo(ref i);
// 'i' is 42.
}
在这个例子中,值我
将不会改变,如果美孚()
未实现。
In that example, the value of i
won't change if Foo()
is not implemented.
这篇关于如何返回从C#分部方法的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文