簡體   English   中英

將一個方法參數傳遞給另一種方法-C#

[英]Passing one Method Parameters, To another method - c#

是否可以將參數從一種方法轉換為另一種方法?

基本上我想做的就是重命名一個方法(在我的例子中是.WriteLine()方法),有沒有辦法用我想要的名稱創建一個方法,並讓它接受另一個方法的參數,如下所示:

void Func(Take The parametes of The .WriteLine method) //This is the rename of the method
{
   Console.WriteLine(place them here);
}

基本上我想重命名方法。

如果我正確理解了您的問題,您要做的就是將一個對象傳遞給Func ,該對象應該傳遞給WriteLine方法。

void Func(string SomeParameter) //This is the rename of the method     
{
   Console.WriteLine(SomeParameter);
}

SomeParameter將傳遞給調用Console.WriteLineFunc方法。 將此功能用作:

Func("Hello World");

這應該在輸出屏幕上打印文本“ Hello World”。

暫無
暫無

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

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