C# 从 Private void 获取字符串
我需要从私有空间获取一个字符串 在此代码中需要
protected override void test
teamsitefinal = teamsite
}
此代码中的
private void test2 {
string teamsite = "test"
}
团队站点字符串,我无法更改 private void 或 protected override void
i need to get a string from a private void
in this code in need the teamsite string
protected override void test
teamsitefinal = teamsite
}
from this code
private void test2 {
string teamsite = "test"
}
i can't change the private void or protected override void
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我了解,
test2
是一种声明一个变量的方法,您需要从另一个方法test
中访问该变量 - 如果是这种情况,除非test2< /code> 要么将此字符串的值传递给另一个函数,要么以某种方式返回此字符串的值,但这根本不可能。
字符串
teamsite
仅在该方法执行期间存在于范围内(即,它仅存在)。So as I understand it
test2
is a method which declares a variable which you need to access from within another methodtest
- if this is the case then unlesstest2
either passes the value of this string to another function, or in some way returns the value of this string this simply isn't possible.The string
teamsite
is only in scope (that is, it only exists) during the execution of that method.将字符串分配到类的私有字段中。
Assign the string into a private field of the class.
但你仍然可以重载该函数吗?如果是这样,则将该字符串作为 ref 参数传递,然后函数填充它。
You can still overload the function though? If so then pass the string as a ref parameter and the function then fills it.