当在参数中声明时,如何处置 ID是可置的

本文关键字:ID 何处置 参数 声明 | 更新日期: 2023-09-27 18:27:06

SendEmail("message", "subject", new System.Net.Mail.Attachment(path1), new System.Net.Mail.Attachment(path2));

如何处置参数中的最后两个附件?完成后它会自行处理吗?

当在参数中声明时,如何处置 ID是可置的

你不能

,因为你没有对它们的引用。

将它们移出方法调用:

using (var attachment1 = new System.Net.Mail.Attachment(path1))
using (var attachment2 = new System.Net.Mail.Attachment(path2))
{
    SendEmail("message", "subject", attachment1, attachment2);
}