culture invariant object ToString()
The System.Convert
class has a static ToString
overload that takes an object
.
Convert.ToString(obj, CultureInfo.InvariantCulture);
Based on my benchmarks, this is roughly twice as fast as string.Format(CultureInfo.InvariantCulture, "{0}", value)
and, more importantly, it looks cleaner. However, if you are building a string already, I'd recommend FormattableString.Invariant.
FormattableString.Invariant($"Object value: {obj}")
I think IFormattable
is the relevant interface. It has a ToString
method that lets you specify the format provider, which can be a culture.