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);
}
}
....
}
Như bạn có thể thấy MediaTypeNames AttachmentType
ném lỗi:C# loại tĩnh không thể được sử dụng như các thông số
'System.Net.Mime.MediaTypeNames': static types cannot be used as parameters
cách tốt nhất để đối phó với điều này là gì?
Có thể bạn muốn sử dụng "chuỗi" làm loại. MediaTypeNames có một số lớp được giữ bên trong nó với một số thuộc tính tĩnh trả về chuỗi. – PlayDeezGames
http://stackoverflow.com/questions/5858591/c-sharp-static-types-cannot-be-used-as-type-arguments –