Doubt in the FOR command

Asked

Viewed 18 times

0

Good afternoon, I am a beginner in C# (it is not even 2 days since I started studying) and I would like an explanation of the line:

WriteLine($"{n1:d2} x {n2:d2} = {n1 * n2:d2}");

Relating to that code:

using static System.Console;

public class Program {
    public static void Main() {
        for (int n1 = 1; n1 < 11; n1++) {
            for (int n2 = 1; n2 < 11; n2++){
                WriteLine($"{n1:d2} x {n2:d2} = {n1 * n2:d2}");
            }
            WriteLine();
        }
    }
}

If you can send me a video that teaches how to use Writeline this way, thank you rsrs! Because I don’t understand the logic of $ and of {}.

  • 1

    https://www.marcioalthmann.net/2015/07/c-6-string-interpolation/

  • https://stackoverflow.com/questions/9354154/how-do-i-interpolate-strings

  • related: https://answall.com/questions/93207/string-interpolation-tem-uma-performance-bestque-string-format

  • Video: https://www.youtube.com/watch?v=UFDxqX57eH0

  • The $ symbol is a recent feature added to C# called "String interpolation". Briefly, whenever you find a $ symbol before a string, it means that the values found between {} keys within that string should be treated as expressions, not strings.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.