c# - How to use variable of program class to another class? -


i need use following string variable of program class telnetconnection class,i possible ways not worked , please give me sugessions. thank you.

program class

 class program  {           static void main()     {      string s = telnet.login("some credentials");     }  } 

telnetconnection class

 class telnetconnection  {       public string login(string username, string password, int logintimeoutms)         {              int oldtimeoutms = timeoutms;             timeoutms = logintimeoutms;              writeline(username);              s += read();              writeline(password);              s += read();             timeoutms = oldtimeoutms;             return s;         }   } 

it should this:

public class telnetconnection {   public string login(string username, string password, int logintimeoutms)   {         string retval = "";          int oldtimeoutms = timeoutms;         timeoutms = logintimeoutms;          writeline(username);          retval += read();          writeline(password);          retval  += read();         timeoutms = oldtimeoutms;         return retval ;     }  } 

in program:

class program {           static void main()     {          var telnet = new telnetconnection();          string s = telnet.login("some username", "some password", 123);     }  } 

but seems there code missing in example, implementation of read method.

if want alter program's string variable, can pass method ref keyword:

public class telnetconnection {   public string login(string username,                        string password, int logintimeoutms, ref string retval)   {         //omitted         retval += read();          writeline(password);          retval  += read();         timeoutms = oldtimeoutms;         return retval ;     }  } 

in program:

class program {           static void main()     {          var telnet = new telnetconnection();          string s = "";           telnet.login("some username", "some password", 123, ref s);          //s altered here     }  } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -