开发者

How to define a Method with no return in C# [closed]

开发者 https://www.devze.com 2023-03-16 00:08 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I'm a beginner in C#. I want to define a Method that has an input. And the input will be shown in an a开发者_StackOverflow社区lert box with this Method. In other words, the duty of this method is receiving a variable. Every where that I call this method, the message will be alerted. I want to know how to define and How to call.


your return type should be "void"

for example:

public void showMsg(string text)
{
    MessageBox.Show(text);
}

you would call your method like this:

showMsg("I can has alert?");


All you have to do is declare the return type as void:

public void MyMethod(string input)
{
    MessageBox.Show(input);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消