Recent articles About

Compiling enterprise

Ivan Koshelev blog on software development

Articles for tags 'Escaping' Advanced usage of interpolated strings in C# [2017 August 16] .NET, C#, Strings, Interpolation, Testing, Escaping

One of the best new features of C# 6 was string interpolation. It is much nicer to read, and you no longer had to rely on 3rd party libraries remembering to introduce ‘DoSomethingFormat(string, params object[])’ along with just ‘DoSomething(string)’.

But ‘DoSomethingFormat’ has one big advantage over string interpolation when it came to unit tests – you can assert on particular values direcly, without having to parse them out of an applied string template. If your date or number format suddenly changes, you don’t need to change your Unit Tests (provided, of course, the format itself is not important enough, just the data).

Well, good news – interpolated strings have a rarely mentioned way for you to have the best of both worlds - FormattableString type!

continue reading
Ivan Koshelev photo

I'm passionate for anything that can be programed and automated to make life better for all of us.

Archives

  1. May 2021 (1)
  2. March 2020 (1)
  3. August 2019 (1)
  4. July 2019 (1)
  5. May 2019 (1)
  6. February 2019 (1)
  7. October 2017 (1)
  8. August 2017 (3)
  9. July 2017 (3)
  10. May 2017 (3)

Elsewhere

  1. GitHub@IKoshelev
  2. NuGet@IKoshelev
  3. LinkedIn