I have this method:
namespace MyProject.String.Utils
{
public static class String
{
public static void formatDecimalSeparator(this string paramString)
{
try
{
if (System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator == ",")
{
paramString = paramString.Replace(".", ",");
}
else
{
paramString = paramString.Replace(",", ".");
}
}
catch
{
throw;
}
}
}
}
But when I do this:
string myString = "1.23";
myString.formatDecimalSeparator();
The result is not "1,23". The variable is not updated. So I have to change the method to return a string and assign the return value to the same variable.
Why is the variable not updated at the call site? The extension method gets the value of the variable paramString
, I can change it in the method, but in the main code the variable is not changed?