Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在类似“设置类型”的方法中设置参数_C#_.net_Variables_Methods_Parameters - Fatal编程技术网

C# 如何在类似“设置类型”的方法中设置参数

C# 如何在类似“设置类型”的方法中设置参数,c#,.net,variables,methods,parameters,C#,.net,Variables,Methods,Parameters,我想用一些设置创建方法,当然我可以使用int-Para,然后使用if==1,if==2等的一些ifs,但我不想这样。我的谷歌技能不允许我搜索解决方案,因为我遗漏了一些单词或其他东西,一些短语。我想让它看起来像: void Method(int var1, int var2, Settings.type.type1){ if(type1){ } if(type2){ } if(type3){ } } 在框架中的一些方法中,我看到了类似这样的东西:templateType.Defoul

我想用一些设置创建方法,当然我可以使用int-Para,然后使用if==1,if==2等的一些ifs,但我不想这样。我的谷歌技能不允许我搜索解决方案,因为我遗漏了一些单词或其他东西,一些短语。我想让它看起来像:

void Method(int var1, int var2, Settings.type.type1){

if(type1){


}
if(type2){


}
if(type3){

}
}
在框架中的一些方法中,我看到了类似这样的东西:templateType.DefoultTemplate。 我不要绳子!我想要清楚的参数。
对不起,我的英语是

创建枚举
设置类型
并将这些值添加到其中。然后,只需添加switch case即可完成所有有条件的操作

因此,您可以访问它,如
SettingsType.Type1
等。

您正在寻找和:


很抱歉,你的目标还不清楚。对一个模糊问题的模糊回答。比如代码中的一个例子呢?@DonBoitnott这些问题都有这样的答案:)他说他自己在谷歌上找答案时漏掉了一个单词或短语。我相信他在寻找使用
类型的“enum”会非常糟糕……这是一个类名。@DonBoitnott-同意。修改。这么快回答:)这就是我要找的thx。我会很高兴,如果有人将编辑和更正我的语法后,如果有人有一些更好的想法,为标题,这将是很好的
public enum CustomType {
      Type1 = 1,
      Type2 = 2,
      Type3 = 3
 };

public void Method(CustomType t)
{
    switch (t)
    {
        case CustomType.Type1:
                  // code here
                  break;
        case CustomType.Type2:
                  // code here
                  break;
        case CustomType.Type3:

    }
}