0
public static class Abc
{
    public const string Placeholder = "{$content}";
    public const string Pattern = $"<div class=\"embed-responsive\">{Placeholder}</div>";
}

How to correctly solve this to avoid breaching DRY (Dont repeat yourself)? I know I can use static readonly, but then it is a bit of a different thing (even though it works..). I think there should be better way? Or is there really not?

M.kazem Akhgary
  • 17,601
  • 7
  • 53
  • 108
NeverStopLearning
  • 938
  • 10
  • 20

1 Answers1

3

While you cannot call a method to initialize a constant value, it is allowed to use operators. If you need to create a constant that contains another constant value, use the plus operator to concatenate string values.

public static class Abc
{
    public const string Placeholder = "{$content}";
    public const string Pattern = "<div class=\"embed-responsive\">" + Placeholder + "</div>";
}
Uranus
  • 1,681
  • 1
  • 12
  • 22