C# 静的型はパラメータとして使用できません 質問する

C# 静的型はパラメータとして使用できません 質問する
public static void SendEmail(String from, String To, String Subject, String HTML, String AttachmentPath = null, String AttachmentName = null, MediaTypeNames AttachmentType = null)
{
    ....

    // Add an attachment if required
    if (AttachmentPath != null)
    {
        var ct = new ContentType(MediaTypeNames.Text.Plain);
        using (var a = new Attachment(AttachmentPath, ct)
                    {
                        Name = AttachmentName,
                        NameEncoding = Encoding.UTF8,
                        TransferEncoding = TransferEncoding.Base64
                    })
        {
            mailMessage.Attachments.Add(a);
        }
    }

    ....
}

ご覧のとおり、MediaTypeNames AttachmentTypeエラーが発生します:

'System.Net.Mime.MediaTypeNames': static types cannot be used as parameters

これに対処する最善の方法は何でしょうか?

ベストアンサー1

静的型をパラメータとしてメソッドに渡すことはできません。その場合、インスタンス化する必要があり、クラスのインスタンスを作成できないためですstatic

おすすめ記事