Member-only story
Why you shouldn’t use String concatenation in your code
Bending the Clean Architecture Principles
Introduction
String concatenation might appear to be a trivial aspect of programming, but in my experience, it has often played a crucial role in the success of multiple projects I’ve worked on. Yet, most developers deem this topic as minimal, small or irrelevant for their use case.
Let’s explore why !
What is string composition?
This is just a fancy word for managing strings, we’re talking about:
- Concatenation
- Interpolation
Concatenation Examples
Programming languages have all sort of ways to concatenate strings. In C#, here a different ways to manipulate string from the top of my head (feel free to comment one if I missed anything) :
1) Standard Operators (+ and +=)
One of the first and common ways to concatenate strings:
var result = "Hello, " + "World!";
2) Using string.Concat
var result = string.Concat("Hello, ", "World!");