URL is a string, so why can’t I concatenate like so:
string url = "something";
url + string.Format("group={0}&", Id);
Is this because string is a reference type, and it’s actually trying to add it to the reference rather than the object?
What is the best way to achieve what I want?
Several answers mention immutability, and that’s not what this is.
The line of code
Is simply not legal as a standalone statement. You will get the error
Making
System.Stringmutable would not change this. Making+mutate one or both of the operands would not change this. The line of code simply is not legal.To be clear, you can define your own type, define a
+operator, inside the method of that operator mutate one of the operands (which would probably anger your consumers, mutable type or not), and then return it, and it still would not make the standalone linea + b;legal. You must use its result in something that is involved in one of the above expressions (assignment, call, etc.).