-3

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);***

3
Contributors
3
Replies
30
Views
4 Years
Discussion Span
Last Post by deceptikon
1

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);
Votes + Comments
Well said.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.