1

I want to call some method in curly brackets in a comment, for example like this:

$"{global::Company.Company.Helpers.Method()}_{Parameters.ProcessName}";

But in this situation everything behind the colon become a comment. Is there a way to use double colon in curly brackets in comment in C#?

dbc
  • 104,963
  • 20
  • 228
  • 340
Kacper Sierakowski
  • 178
  • 1
  • 3
  • 10

1 Answers1

2

This is likely due to the way that string formatting works - {thing:A} will format thing with "A" as format information. For example, formatting an enum as {myEnumValue:D} will use the integer value, but {myEnumValue:G} will use the name of the enum value.

You can work around this by wrapping the colon-containing expression in parentheses, like so:

$"{(global::Company.Company.Helpers.Method())}_{Parameters.ProcessName}"
yaakov
  • 5,552
  • 35
  • 48