From the course: C# and .NET Essential Training
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
String formatting - C# Tutorial
From the course: C# and .NET Essential Training
String formatting
- In the previous video, we saw how to use interpolation to insert data into strings. And now we're going to see how to exert finer grain control over the formatting of the data. So as we've already seen there are a couple of ways to insert data into strings. There's the old school way of using indexes along with the names of the variables, and then there's the interpolation method where you just use the name of the variable inside the curly braces and you put a dollar sign at the outside start of the string. There are some optional parameters that you can supply as part of the string to control the formatting. And I've highlighted them here in the square brackets. The alignment value can be either a positive or negative number and is used to determine the character width of the field when the data is formatted. If the number is positive, then the field is right aligned. And if it's negative, then the field is left aligned.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.