Do you use string interpolation when formatting strings

Updated by Tom Bui [SSW] 1 year ago. See history

123
<introEmbed body={<> String Interpolation - greatly reduces the amount of boilerplate code required when working with strings Formatting strings on the fly was previously a task which required a stack of boilerplate code </>} />
var s = String.Format("Profit is ${0} this year", p.TotalEarnings - p.Totalcost);

❌ Figure: Figure: Bad Example - Using String.Format() makes the code difficult to read

var s = "Profit is ${p.TotalEarnings - p.Totalcost} this year";

✅ Figure: Figure: Good Example - String Interpolation is very human readable

Acknowledgements

Liam Elliott
Matt Wicks
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star