枚举作为可选参数 [英] Enum as a optional parameter

查看:96
本文介绍了枚举作为可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试使用枚举作为可选参数。但我得到错误说标识符预期。谁能告诉我如何使用枚举;

我尝试过以下代码;

Hello all,

I am trying to use an enum as a optional parameter. But i get en error saying "identifier expected". Can anyone tell me how to use enum;
I have tried the following code;

enum attachmentType { filePath , fileString}; 
public static void SendEmail(attachmentType = attachmentType.filePath)
{
  // Do stuff
}



我也发现了这个链接 [ ^ ]。这是一个类似的问题,但答案并不令人满意。



提前谢谢。


I have also found this link[^]. It is a similar question but the answer is not satisfactory.

Thanks in advance.

推荐答案

你仍然需要为参数声明一个名称。尝试将其更改为;



You still need to declare a name for parameter. Try changing it to;

public enum attachmentType { filePath , fileString};

public static void SendEmail(attachmentType type = attachmentType.filePath)
{
  // Do stuff
}







希望这有帮助,

Fredrik




Hope this helps,
Fredrik


应该是这样的:



Should be like this:

enum attachmentType { filePath , fileString};
public static void SendEmail(attachmentType type = attachmentType.filePath)
{
  // Do stuff
}





您缺少参数名称。



You are missing the parameter name.


这篇关于枚举作为可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆