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
  • 18,645
  • 8
  • 57
  • 118
NeverStopLearning
  • 958
  • 11
  • 21

1 Answers1

4

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,690
  • 1
  • 12
  • 22