我需要向用户发送电子邮件通知,我需要允许管理员为消息正文(可能还有标题)提供模板。
我想要像 string.Format
这样的东西,它允许我提供命名的替换字符串,所以模板看起来像这样:
Dear {User},
Your job finished at {FinishTime} and your file is available for download at {FileURL}.
Regards,
--
{Signature}
对我来说最简单的方法是什么?
最佳答案
以下版本适用于可以使用新版 C# 的用户:
// add $ at start to mark string as template
var template = $"Your job finished at {FinishTime} and your file is available for download at {FileURL}."
在一行中 - 这是现在完全支持的语言功能(字符串插值)。
关于c# - 在 .NET 中进行字符串模板化的好方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/733378/