I know 4 different types of concatenation of string in 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 each command is for, but I would like to know what impact it has on memory and performance.
Ex: if I am not mistaken in concatenation using "+"
"texto1" + "texto2"
It would have 2 references in memory "texto 1"
, "texto2"
and when it concatenates it creates a third with result "texto1 texto2"
.
How does it work in other cases? Or if what I explained was wrong (it was more to make it easier to understand my doubt).
Because I use Resharper and it always recommends the string interpolation and the verbating string and I would like to know how easy it is to read and how it disrupts performance and memory recycling.
An example of the code that Resharper suggests for me to use the verbating string
var texto = "texto";
Hesuggeststhatyoustay:
vartexto=@"texto"
Itsuggestsmovingresourcetostringorusingverbatingstring,andalsosuggestscreatingaconstantforthestringthatitpointsto.
How far does it make it easier and when does it get in the way?