SSW Foursquare

Do you use string interpolation when formatting strings

Last updated by Tom Bui [SSW] 8 months ago.See history

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: Bad Example - Using String.Format() makes the code difficult to read

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

Figure: Good Example - String Interpolation is very human readable

We open source. Powered by GitHub