I was not lucky in my 15 minutes googling. Maybe bad luck with good keyword?
Why does the Resharper suggest spliting a string in function parameter?
Example:
From this:
return PartialView("Categorias", lista);
To this:
return PartialView("Cat" + "egorias", lista);
I checked documentation here: link
And it says: Split string literal - Splits string literal into two literals.
I want to discover why is this a good practice, what are the fundamental idealogic behind the scenes that achieved this practice.
I don't want to do it without knowing why...
Easy, use triple quotes to start and end them. s = """ this is a very long string if I had the energy to type more and more ...""" You can use single quotes too (3 of them of course at start and end) and treat the resulting string s just like any other string.
If you want your string to span multiple lines, you have to concatenate multiple strings: String myString = "This is my string" + " which I want to be " + "on multiple lines."; It gets worse though. If you want your string to actually contain new lines, you need to insert \n after each line.
This is not a good practice. Not everything ReSharper suggests is a good practice - it just so happens that your cursor is in that position, so ReSharper gives you the option to split the string. Try it in any string in any position.
ReSharper has similar position based utilities, for example "convert to verbatim string" or "convert to regular string" - neither of which is "better".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With