我有这个类。使用struct字段作为参数
public class EmailManager
{
public struct AttachmentFormats
{
public const string Excel = ".xlsx";
public const string Pdf = ".pdf";
}
private static bool SendEmail(string to, string from, ???)
{
/*??? is one of the AttachmentFormats*/
}
}
当用户想要使用SendEmail
,我想限制他们只使用定义AttachmentFormats之一。像
EmailManager.SendEmail("xxx","yy",EmailManager.AttachmentFormats.Excel);
这是可能的。如果是的话,我该怎么做。
定义枚举,而不是struct。 –
然后,该值将是一个int,然后我必须再次写入扩展方法。对。我认为这会更简单。 – Qwerty
int !!为什么?你将会在你的问题“EmailManager.AttachmentFormats.Excel”中提到你的价值。为了提供有限的选项,我觉得枚举是最好的选择。也在sendEmail()你想得到“.xlsx”? –