开发者

C# Get String from Private void [closed]

开发者 https://www.devze.com 2023-03-20 20:25 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the h开发者_开发百科elp center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消