【发布时间】:2015-09-08 10:19:13
【问题描述】:
我有一个常量,它返回异常文本。在这个常量中,我有一个必须使用的占位符。我应该如何使用这个占位符?
这是我的代码:
public static class Messages
{
public const string ShipDestroyed = "{0} has been destroyed";
}
我在另一个类中使用了这个方法中的常量:
protected void ValidateAlive(IStarship ship)
{
if (ship.Health <= 0)
{
throw new ShipException(Messages.ShipDestroyed);
}
}
我想将“ship.Name”属性放入占位符中。
【问题讨论】:
-
检查你的课程笔记总是个好主意 - 家庭作业经常涉及最近的主题(可能是“C#中的字符串格式”)。
标签: c# constants placeholder