I've read both
Optional parameters "must be a compile-time constant"
And
Default parameter for value must be a compile time constant?
But this keeps not compiling on the declaration, marking Empty
as a non constant.
public class MyClass
{
private const string Empty = string.Empty;
private string WriteFailedList(string prefix = Empty, DeployResponse Ret)
{
StringBuilder sb = new StringBuilder();
var errorItems = Ret.Items.TakeWhile(item => item.Status == DeployItem.ItemStatus.Error);
foreach (var item in errorItems)
sb.AppendLine(string.Format("{0} {1}",prefix,item.Filename));
return sb.ToString();
}
}
@Edit: Code good practice suggestions taken from Jon Skeet.