I think everyone knows that strings ( System.String ) are immutable in nature. Therefore, often working with methods such as string.ToUpper() and others, creates a new object that is almost identical to the previous one.
I don’t even want to find out the reasons for this, I clearly have a smaller mind than the guys who invented such a wrapper over the Char array, but you can still change the lines, at least through pointers.
Wrote such an expanding method:
public static unsafe String ToUpperUnsafe ( this String value ) { fixed ( Char* arrChr = value ) { for ( var i = 0 ; i < value.Length ; ++i ) { var temp = Char.ToUpper( value[ i ] ); arrChr[ i ] = temp; } } return value; } As you can see, one object is accepted as input, changes and returns without cloning. The question is how safe it is. I looked through the source code of the original method, there are a lot of things that I did not understand, because of this, the thought arose that in certain situations it might not work.
ps By the way, the vanilla method works faster, but this one wins in the memory.