0

I have the following bit of code:

public static string GetDomainRole(string role)
{
    return $"{Startup.Configuration["Domain:Name"]}\\{role}";
}

Where

Startup.Configuration["Domain:Name"] = "MyDomain"
role = "SomeDomainRole"

And neither have anything other than a -> z, A -> Z, _ for their characters.

If I remove the first \, then I get an error saying:

A '{' may only be escaped by doubling '{{' in an interpolated string

The problem is, my resultant string from GetDomainRole(...) is:

MyDomain\\SomeDomainRole

With the double \\. This obviously does not match my domain role MyDomain\SomeDomainRole.

I'm sure I'm missing something really small here, but I can't for the life of me figure out how to get rid of the double \\.

EDIT

Appears I just needed to adjust my search terms. This is a duplicate of How to use escape characters with string interpolation in C# 6?

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
JosephGarrone
  • 4,081
  • 3
  • 38
  • 61
  • How are you determining that the return value of `GetDomainRole` contains two backslashes? If you're viewing it in the debugger it's very possible that the debugger is showing you the *escaped* version of the string, so it's showing the backslash as escaped. – Kyle Feb 23 '16 at 05:26
  • @Kyle you are correct. It was. Problem was *when* I was inspecting the value... – JosephGarrone Feb 23 '16 at 05:30

0 Answers0