Chapter 9. Stringy features

 

This chapter covers

  • Using interpolated string literals for more-readable formatting
  • Working with FormattableString for localization and custom formatting
  • Using nameof for refactoring-friendly references

Everyone knows how to use strings. If string isn’t the first .NET data type you learned about, it’s probably the second. The string class itself hasn’t changed much over the course of .NET’s history, and not many string-oriented features have been introduced in C# as a language since C# 1. C# 6, however, changed that with another kind of string literal and a new operator. You’ll look at both of these in detail in this chapter, but it’s worth remembering that the strings themselves haven’t changed at all. Both features provide new ways of obtaining strings, but that’s all.

Just like the features you saw in chapter 8, string interpolation doesn’t allow you to do anything you couldn’t do before; it just allows you to do it more readably and concisely. That’s not to diminish the importance of the feature. Anything that allows you to write clearer code more quickly—and then read it more quickly later—will make you more productive.

9.1. A recap on string formatting in .NET

 
 

9.2. Introducing interpolated string literals

 
 
 

9.3. Localization using FormattableString

 
 
 

9.4. Uses, guidelines, and limitations

 
 

9.5. Accessing identifiers with nameof

 
 
 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest