簡體   English   中英

c# 控制台應用程序創建公共靜態類並在此類中創建另一個靜態方法

[英]c# console app crating public static class and in this class make another static method

如何創建一個名為 Test1 的公共靜態類。 這個類包含一個名為 Test2 的靜態方法,它接受三個整數作為輸入,並返回一個字符串作為輸出。 我如何在我的 program.cs 中調用它

要創建靜態類,只需在創建類時將“靜態”一詞放在“類”一詞之前。 對於靜態方法,靜態一詞就在返回類型(在本例中為字符串)之前。 要調用靜態方法,只需使用 class.method。 例如,對於您的代碼,它將是 Test1.Test2。

public static class Test1
{
    public static string Test2(int a, int b, int c)
    {
        return string.Empty;
    }
}

class Program
{

    public static void Main(string[] args)
    {
        string result = Test1.Test2(1, 2, 3);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM