6
I know 4 different types of concatenation of string in the c#:
// string Interpolation
$"valor {variavel} R$";
// Verbating string
@"texto qualquer
pula a linha e continua o texto";
// concatenar 2 strings
"texto" + "texto";
// string.format
String.Format(variavel, " R$");
// Verbating string com string Interpolation
$@"UPDATE {variavel}
SET campo = {variavel2}";
Until then I know what serves each of the commands, more I would like to know what impacts they have on memory and performance.
Ex: if I’m not mistaken the concatenation using the "+"
"texto1" + "texto2"
He’d have two references in his memory "texto 1"
, "texto2"
and when it concatenates it creates a third with the result "texto1 texto2"
.
How does it work in other cases? Or if what I explained this wrong (was more to make it easier to understand my doubt).
Because I use Resharper and he always recommends string Interpolation and the verbating string and I would like to know how far it facilitates reading and how far it disrupts performance and memory recycling.
An example of the code that Resharper suggests for me to use verbating string
var texto = "texto";
he suggests you stay:
var texto = @"texto"
He suggests moving to the Resource to string or use the verbating string, and also suggests creating a constant for the string that he points to.
As far as it goes and when it gets in the way?
Verbatim with interpolation? This one I didn’t know...
– Jefferson Quesado
@JeffersonQuesado https://answall.com/search?q=verbatim+interpola%C3%A7%C3%A3o
– Maniero
@Maniero c# always being beautiful
– Jefferson Quesado
@Maniero I added an example that happens with the suggestion of
resharper
with the prints, in the case when using a direct string as in the example he suggests this edition tointerpolation string
– Nicolas Sylverio
He allows to do, it is not that he suggests, it may be that he wishes this among other things, he is not saying that it is better to do so.
– Maniero