gpt4 book ai didi

c# - 显示字符串中的字符串列表

转载 作者:行者123 更新时间:2023-11-30 19:38:06 27 4
gpt4 key购买 nike

好的,我在这里尝试向用户发送一封关于无效附件的电子邮件。我在之前的函数中收集了无效附件名称(字符串)的列表,然后我试图发送一封电子邮件,其中列出所有被视为无效的附件。不知道如何处理这种情况。我有下面的例子

List<string> invalidType = new List<string>();

if (invalidType != null)
{
emailInvalidBody = new ItemBody
{
Content = " Expense attachements recieved with subject line [ "
+ email.Subject
+ " ] sent at [ "
+ email.DateTimeReceived.Value.DateTime.ToLocalTime()
+ " ] had the following invalid attachments ["
+ invalidType
+ "]. Please make sure all attachment's are images or PDF's.",
};
}
List<Recipient> emailInvalidRecipients = new List<Recipient>();
emailInvalidRecipients.Add(new Recipient
{
EmailAddress = new EmailAddress
{
Address = email.Sender.EmailAddress.Address
}
});
Message invalidEmailMessage = new Message
{
Subject = "Invalid Expenses",
Body = emailInvalidBody,
ToRecipients = emailInvalidRecipients
};
starBox.Users[EMAILBOX].SendMailAsync(invalidEmailMessage, false).Wait();

我的最终目标是拥有一个将执行以下操作的电子邮件正文

"Expense attachements recieved with subject line Subject sent at 8:00 1/29/16 had the following invalid attachments [ invalidattachment1 invalidattachment2 invalidattachment3 invalidattachment4 ]. Please make sure all attachment's are images or PDF's.",

最佳答案

使用 string.Join 转换您的 List<string>在所有项目连接在一起的列表中

List<string> invalidType = new List<string>();
.....

// Probably you don't need to check for null but for element count.
// However it doesn't hurt to be a little defensive...
if (invalidType != null && invalidType.Count > 0)
{
string attachments = string.join(",", invalidType);
emailInvalidBody = new ItemBody
{
Content = " Expense attachments received with subject line [ " +
email.Subject + " ] sent at [ " +
email.DateTimeReceived.Value.DateTime.ToLocalTime() +
" ] had the following invalid attachments [" +
attachments + "]. Please make sure all " +
" attachment's are images or PDF's.",
};

}

关于c# - 显示字符串中的字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35091826/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com