我正在尝试开发自定义输入对话框。在它的构造函数中,我想采用如下参数 -
PromptType.Question
PromptType.Information
PromptType.Feedback
//etc....
private void buttonTest_Click(object sender, System.EventArgs e)
{
InputBoxResult result = InputBox.Show("Some title",PromptType.Question);
}
我该怎么办?
答案 0 :(得分:3)
你想要的是一个枚举:
public enum PromtType
{
Question,
Information,
Feedback
}
public class InputBox
{
public static void Show(PromtType type)
{
//...
}
}
InputBox.Show(PromtType.Question);
答案 1 :(得分:1)
您可以使用枚举方法,并在switch语句中捕获所选选项
public enum PromtType
{
Question,
Information,
Feedback
}
public class InputBox
{
public static void Show(PromtType type)
{
switch(type)
{
case PromtType.Question:
//do question things here
break;
case PromtType.Information:
//do information things here
break;
case PromtType.Feedback:
//do feedback things here
break;
}
}
}
InputBox.Show(PromtType.Question);