gpt4 book ai didi

c# - 如何从 C# 部分方法返回值?

转载 作者:可可西里 更新时间:2023-11-01 08:03:36 25 4
gpt4 key购买 nike

有没有办法这样做,因为部分方法似乎必须返回 void(我真的不明白这个限制,但顺其自然吧)?

最佳答案

好吧,从技术上讲,您可以从部分方法“返回”一个值,但它必须通过 ref 参数,所以这很尴尬:

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.
}

在该示例中,如果未实现 Foo()i 的值将不会更改。

关于c# - 如何从 C# 部分方法返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4857315/

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