简体   繁体   中英

c# How to get dynamically created object

I have a method that creates client and i have another method that must use created specific client but i dont know how to get that specific client.

   private void CreateClient(string username, string token,string mail, string mailpass)
   {
            Client client = new Client();
            //...
   }
  private void CreateLive(string username)
  {
            //How to get createclient method's client.
            //...
  }

Generally you want to have your function provide a return value. In this case your CreateClient function can return your created Client object;

// updated to return Client object
private Client CreateClient(string username, string token,string mail, string mailpass)
{
    Client client = new Client(); // create client
    return client; // return client to caller
}

private void CreateLive(string username)
{    
    Client myClient = CreateClient(username, "sometoken","myname@someplace.com","1234");
    // now I can do things with myClient ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM