繁体   English   中英

c# 如何获得动态创建的 object

[英]c# How to get dynamically created object

我有一个创建客户端的方法,我有另一种必须使用创建的特定客户端的方法,但我不知道如何获取该特定客户端。

   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.
            //...
  }

通常你想让你的 function 提供一个返回值。 在这种情况下,您的CreateClient function 可以返回您创建的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 ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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