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 {}
.
https://www.marcioalthmann.net/2015/07/c-6-string-interpolation/
– novic
https://stackoverflow.com/questions/9354154/how-do-i-interpolate-strings
– novic
related: https://answall.com/questions/93207/string-interpolation-tem-uma-performance-bestque-string-format
– novic
Possible duplicate of What does the symbol "$" mean before a string?
– EmanuelF
Video: https://www.youtube.com/watch?v=UFDxqX57eH0
– novic
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.
– Bruno Soares