Why does Visual Studio create double closing brackets for interpolated C # 6 lines?

In Visual Studio 2015, when I move on to writing an interpolated string in a variable by entering the opening braces '{', to achieve the following:

var a = $"{}"; 

the second end bracket is automatically inserted, painted red or pink, so that

 var a = $"{}}" 

After inserting the variable inside the brackets '{}' and trying to compile, Visual Studio throws an error: "Character CS8086: A" should be escaped (by doubling) in the interpolated line. ". It makes sense, but doesn’t at all explain why the second“! ”Appeared first! I didn’t want to write the alphabetic character '}'; I just wanted to write a regular interpolated line - one '}' for one '{'. Each time when I use interpolated strings, I am forced to manually remove this anomalous second closing bracket for successful compilation.

Most curious, it seems that this is not all the time. If you remove "{}}" from your interpolated string and type "{" again, you will get "{}" - just like you expected in the first place.

What about this behavior?

+7
c # visual-studio-2015
source share
1 answer

This is called Resharper.

You can prove it by choosing

Tools | Options | ReSharper | General | Pause now

then try again. Optional } will not appear. (I tried with R # 10.0)

I worked on this issue by pressing ^ Z after R # inserted an optional } , but it is still a little annoying.

I assume that this should be reported as an error on the R # site (unless it has been fixed with a recent version).

[EDIT] I reported this as a bug in the Resharper forums . My bug report should appear there as soon as the mod approves it.

+6
source share

All Articles