[英]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.