rjmurillo / EffectiveCSharp.Analyzers

Many of the recommendations in the book Effective C#: 50 Specific Ways to Improve Your C# can be validated by Roslyn-based analyzers and code fixes.
MIT License
2 stars 1 forks source link

Item 5: Prefer FormattableString for Culture-Specific strings #29

Closed rjmurillo closed 2 months ago

rjmurillo commented 2 months ago

Related: https://github.com/BillWagner/EffectiveCSharpAnalyzers/issues/5, #28

string first = $"It's the {DateTime.Now.Day} of the {DateTime.Now.Month} month";

FormattableString second = $It's the {DateTime.Now.Day} of the {DateTime.Now.Month} month";

The compiler generates different code depending on the compile-time type of the output being requested. The code that generates a string will format that string based on the current culture of the machine.