C# 使用带参数的方法

C# 使用带参数的方法,c#,methods,parameters,messagebox,C#,Methods,Parameters,Messagebox,我想使用一种方法创建一个消息框: public class Layout { public void MBox(string msgText, string msgCaption, MessageBoxButtons msgButton, MessageBoxIcon msgIcon) { MessageBox.Show(msgText, msgCaption, msgButton, msgIcon); } } 现在,我尝试使用以下代码打开它: Layo

我想使用一种方法创建一个消息框:

public class Layout
{
    public void MBox(string msgText, string msgCaption, MessageBoxButtons msgButton, MessageBoxIcon msgIcon)
    {
        MessageBox.Show(msgText, msgCaption, msgButton, msgIcon);
    }
}
现在,我尝试使用以下代码打开它:

Layout _layout = new Layout();
_layout.MBox("Hello", "Hello again", OK, None);

不幸的是,应用程序不知道“OK”和“None”。我犯了什么错?你能帮帮我吗?提前谢谢。亲切的问候!;)

您需要提供以下类型:

_layout.MBox("Hello", "Hello again", MessageBoxButtons.OK, MessageBoxIcon.None);
此外,您还可以使用默认参数缩短默认情况:

public void MBox(string msgText, string msgCaption, 
    MessageBoxButtons msgButton = MessageBoxButtons.OK, 
    MessageBoxIcon msgIcon = MessageBoxIcon.None)
{
    MessageBox.Show(msgText, msgCaption, msgButton, msgIcon);
}
如果这两个参数分别为
Ok
None
,则您可以忽略这两个参数:

_layout.MBox("Hello", "Hello again");

您需要提供以下类型:

_layout.MBox("Hello", "Hello again", MessageBoxButtons.OK, MessageBoxIcon.None);
此外,您还可以使用默认参数缩短默认情况:

public void MBox(string msgText, string msgCaption, 
    MessageBoxButtons msgButton = MessageBoxButtons.OK, 
    MessageBoxIcon msgIcon = MessageBoxIcon.None)
{
    MessageBox.Show(msgText, msgCaption, msgButton, msgIcon);
}
如果这两个参数分别为
Ok
None
,则您可以忽略这两个参数:

_layout.MBox("Hello", "Hello again");

您需要提供以下类型:

_layout.MBox("Hello", "Hello again", MessageBoxButtons.OK, MessageBoxIcon.None);
此外,您还可以使用默认参数缩短默认情况:

public void MBox(string msgText, string msgCaption, 
    MessageBoxButtons msgButton = MessageBoxButtons.OK, 
    MessageBoxIcon msgIcon = MessageBoxIcon.None)
{
    MessageBox.Show(msgText, msgCaption, msgButton, msgIcon);
}
如果这两个参数分别为
Ok
None
,则您可以忽略这两个参数:

_layout.MBox("Hello", "Hello again");

您需要提供以下类型:

_layout.MBox("Hello", "Hello again", MessageBoxButtons.OK, MessageBoxIcon.None);
此外,您还可以使用默认参数缩短默认情况:

public void MBox(string msgText, string msgCaption, 
    MessageBoxButtons msgButton = MessageBoxButtons.OK, 
    MessageBoxIcon msgIcon = MessageBoxIcon.None)
{
    MessageBox.Show(msgText, msgCaption, msgButton, msgIcon);
}
如果这两个参数分别为
Ok
None
,则您可以忽略这两个参数:

_layout.MBox("Hello", "Hello again");

您必须使用
MessageBoxButton.OK
MessageBoxIcon.None


是要在messagebox中显示的可能按钮的枚举。这同样适用于。

您必须使用
MessageBoxButton.OK
MessageBoxIcon.None


是要在messagebox中显示的可能按钮的枚举。这同样适用于。

您必须使用
MessageBoxButton.OK
MessageBoxIcon.None


是要在messagebox中显示的可能按钮的枚举。这同样适用于。

您必须使用
MessageBoxButton.OK
MessageBoxIcon.None


是要在messagebox中显示的可能按钮的枚举。同样的道理也适用于您。

谢谢您的帮助!;)谢谢你的帮助!;)谢谢你的帮助!;)谢谢你的帮助!;)谢谢你的帮助!;)谢谢你的帮助!;)谢谢你的帮助!;)谢谢你的帮助!;)