I have been coding with c# for a last couple of months now, but every time I concatenate I always get confused between the difference between the comma ,
and the pl
The comma is used as a separator while formatting strings, while the plus sign is used for normal concatenation.
Formatting is where you have placeholders such as {0}
and {1}
. Other strings, separated by commas, are used to fill these placeholders. Note that the commas are not operators and are simply used to separate parameters. This outputs Hello world!
:
string greet = "Hello";
Console.WriteLine("{0}{1}", greet, " world!");
Concantenation is more straight forward. It simply combines the strings in order. Same example but with concatenation:
string greet = "Hello";
Console.WriteLine(greet + " world!");
Edit: now that you have included the specific problem, here's what you can try:
Console.WriteLine("Your id is: {0}" , id++);