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
So as I understand it test2
is a method which declares a variable which you need to access from within another method test
- if this is the case then unless test2
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.
class MyClass : SomeBaseClass
{
string teamsite;
protected override void test ()
{
string teamsitefinal = teamsite;
}
private void test2 ()
{
teamsite = "test";
}
}
You can still overload the function though? If so then pass the string as a ref parameter and the function then fills it.
精彩评论