var item1 := “123”;
var item2 := “234”;
var tst := $“an {item1}”;
var tst
The last line has coloring problems (color of a string).
During the typing you will see that the third line has red underlining (but will compile)
When you remove the fourth line, the last } will get red underlining.
change the third line in
var tst := $"an {item1} and ";
The word “and” become blue, but is part of the string (but will still compile)
If you add the next {item2} to the string, it is seen as comment, so no CC.
var tst := $"an {item1} and {item2} ";
Change the line to:
var tst := $“embedded interpolated string: {if item2=“123” then $“here is {item1}” else {item2})}”
Cant you just do for the Moment the usual way over string concationation?
It is often even more performant than Interpolation, of cause, depends on the internal implementation, but in MS C# (which sould be good optimized) you have this nice benchmark
I use this for SQL statements, making it easy to copy / past it in the Management studio.
Because all vars are with {}, it is easy to replace them and run / test the query.
It is also easier typed and better readable - thus better maintainable.
It was never mend for performance.
The implementation of MS is String.Format.
But the good implementation should be:
step 1: remove the $
step 2: replace “{ by (
step 3: replace }” by )
step 4: replace { by " + (
step 4: replace } by ) + "
So:
var tst := $“embedded interpolated string: {if item2=“123” then $“here is {item1}” else $”{item2}“} and some more text”
after step 1:
var tst := “embedded interpolated string: {if item2=“123” then “here is {item1}” else “{item2}”} and some more text”
after step 2:
var tst := “embedded interpolated string: {if item2=“123” then “here is {item1}” else (item2}”} and some more text"
after step 3:
var tst := "embedded interpolated string: {if item2=“123” then “here is {item1) else (item2)} and some more text”
after step 4:
var tst := "embedded interpolated string: " + (if item2=“123” then “here is " + (item1) else (item2)} and some more text”
after step 5 (and done):
var tst := "embedded interpolated string: " + (if item2=“123” then “here is " + (item1) else (item2)) + " and some more text”
And that’s why I need / want the string obfuscation too; I use temporary encrypted stored procedures to make sure that the SQL code hidden from the SQL Profiler, but it can still be seen in my application.
Logged the editor handling. I’m still having a hard time seeing any real advantage to supporting nested interpolated strings, especially considering the massive amount of work it is to do so.
I vote against them. how deeply would they nest? can the nested interpolated stirring contain more nested interpolated strings? caudal they be 43 levels deeply nested in theory?