From the course: Learning C#

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

String formatting

String formatting - C# Tutorial

From the course: Learning C#

String formatting

- [Instructor] All right, let's take a deeper look at Formatting Strings. So here in the formatting folder I'm going to open up the program CS file. So far during this course, I've been using the curly brace with index notation to print strings with the values of variables inserted into them. And that's similar to what I have here in my code when I'm printing the strl one variable on this line. Now we can use the same mechanism to get more control over how data is formatted into the string. And the general format for doing this is by specifying the index, which is what we've been doing. And you can see that this is the general format right here. So we specify the index along with an optional alignment value which we'll talk about in a little bit and then a colon and then a format specifier. So we'll take a closer look at the alignment in a moment but for now we'll just focus on the formatting and there are several formatting…

Contents