namespace APIproject
{
public class ApiCallResponse //class1
class Program //class2
}
我的代碼中有兩個類,它們都在同一個檔案名 Program.cs 中。我想將我的 ApiCallResponse 類轉移到另一個檔案中,例如 Program1.cs 然后我想將新檔案 Program1.cs 呼叫到 Program.cs 中以訪問該類。我怎樣才能做到這一點?
uj5u.com熱心網友回復:
如果你想在一個單獨的檔案中有一個類,這實際上是一種常見的做法,你需要添加一個類檔案 ( *.cs) 并在那里撰寫你的代碼。
在此之后,您需要參考一個包含您的類的命名空間,然后像往常一樣使用您的類:
程式.cs:
using MySolution.Responses; //This is how you can connect different classes.
namespace MySolution
{
public class Program
{
public static void Main(string[] args)
{
var response = new ApiCallResponse();
}
}
}
../Responses/ApiCallResponse.cs:
namespace MySolution.Responses
{
public class ApiCallResponse
{
public ApiCallResponse()
{
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/490871.html
上一篇:在C中運行WinMain的問題
下一篇:成功構建后二進制檔案丟失?
