Printing multiple integers can be done easily!!

WRONG : Console.WriteLine("%d * %d = %d",c,a,b);
***
RIGHT AND PERFECT:: Console.WriteLine("{0} * {1} = {2}",c,a,b);***

Recommended Answers

WRONG : Console.WriteLine("%d * %d = %d",c,a,b);

Of course it's wrong, WriteLine() does not and never has purported to offer printf() style format specifiers. Saying that the above code is wrong is just like saying that the following line is wrong:

Console.WriteLine("FORMAT INT #1 LITERAL(*) …
Jump to Post

All 3 Replies

I should have written that in FORTRAN and say that it is WRONG in C#.

C# is mentioned!

WRONG : Console.WriteLine("%d * %d = %d",c,a,b);

Of course it's wrong, WriteLine() does not and never has purported to offer printf() style format specifiers. Saying that the above code is wrong is just like saying that the following line is wrong:

Console.WriteLine("FORMAT INT #1 LITERAL(*) INT #2 LITERAL(=) INT #3", c, a, b);

It's not even worth mentioning, because it's obvious to anyone who bothered to read a book or reference on C#. Of course, if your taget audience is the folks who learn by random guessing, then it might be helpful.

RIGHT AND PERFECT:: Console.WriteLine("{0} * {1} = {2}",c,a,b);

Actually, I'd wager that your right and perfect answer is actually incorrect. If it's not incorrect, it's misleading because the usual convention is for c to contain the result of a binary operation:

Console.WriteLine("{0} * {1} = {2}", a, b, c);
commented: Well said. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.