3 ms·
Interestingly the two examples work together: the "x" is passed to foo by value, so a copy is modified and then not returned. If you have _mutable_ strings then
by pjc50 9y ago
Interestingly the two examples work together: the "x" is passed to foo by value, so a copy is modified and then not returned. If you have _mutable_ strings then write
void Main()
{
string s = "foobar";
Foo(s);
Console.WriteLine(s);
}
void Foo(string s) => s.Substring(1, 2);
then this example behaves differently from the x one. Unless you copy strings on function call, which is potentially more expensive.