1

Closed

Console.Write / WriteLine should not give a Message

description

Since it's totally legitimate to call
Console.Write(string);
Console.WriteLine(string);
without format arguments, there should be no message about:
Contains no args! Are you sure this Is correct?
Closed Sep 18, 2014 at 10:15 PM by AdamSpeight2008

comments

AdamSpeight2008 wrote May 30, 2014 at 3:09 AM

Yes it legitimate to call without format arguments.

But as I see it, its not so simple as there are a few possible situations.
  • You actually meant the overload with only 1 parameter.
    Console.WriteLine(" {0} ")
    Desired Result: No message.
  • You actually meant the overload with more then 1 parameter but forgot to supply them.
    Console.WriteLine(" {0} ")
    Desired Result: Argument Index out of range.
    The above two are currently (for me) hard to distinguished.
  • You supplied a formatstring and arguments but forgot to put args in the formatstring.
    Console.WriteLine("Your name is ", yourname )
    Desired Result: Contains no args! Are you sure this Is correct?
    This one has been fixed.
How should we decide which message to display in the first two cases?
  • If parameter-args are not present. Don't fully check formatstring just count format-args then display information message Contains no args! Are you sure this Is correct?

AdamSpeight2008 wrote May 30, 2014 at 3:34 AM

I have modified the code to use the following information messages.
  • FormatString contains args but no parameters
    No parameters! Are you sure this Is correct?
  • FormatString contains no args but has parameters
    Contains no args! Are you sure this Is correct?
These just inform the programmer that there could be a problem with the code, but still allow compilation.

AdamSpeight2008 wrote May 30, 2014 at 3:37 AM

  • If the FormatString contains no args and no parameters are supplied.
    No message.

Suchiman wrote May 30, 2014 at 11:47 AM

◾If the FormatString contains no args and no parameters are supplied.
No message.
That was my original Intention which i tried to report, e.g.
Console.WriteLine("Hello World");
gave previously
Contains no args! Are you sure this Is correct?