In Ruby, methods which change the object have a bang on the end: string.downcase!
In c# you have to do: foo = foo.ToLower()
Is there a way to make an extension method like:
foo.ConvertToLower()
that would manipulate foo?
(I think the answer is no since strings are immutable and you can’t do a ref this in an extension method.)
No, you cannot do this in an extension method. To reassign the value of a variable passed in as a parameter you have to pass it by reference using the
refparameter modifier, what is not allowed for extension methods. Even if this would be possible, there might not be a variable to reassign, like in'foo'.ConvertToLower().