In the case where the full text of the format string is static and known at compile time, should the parameter of the format string be absent to be a compile-time error, or at least a warning?
ReSharper catches this, but it is just an underlined curve. I got the impression that this would cause a general compile-time error:
string x = string.Format("soeuotnh {0}");
Is there a way to raise an error warning of this type without having to run my code through FxCop or something like that? Even C / C ++ compilers raise a warning / error for such an obvious error (although they usually do not check type safety).
Microsoft Connect, ,
", , , , , " . , ( ) -, , , ( , const), (), . Visual Studio , MS Connect, : , ... VS, , - .
, ? , , , String.Format #.
String.Format
C; undefined - , , ( ...), , . "", .
, - , , . , Format (String, params Object[]), :
(String, params Object[])
public static string Format( string format, params Object[] args )
: System.String(. ).: System.Object [] , .
: System.String(. ).
: System.Object [] , .
params ( ), .
params
Edit:
, . , , Resharper, , .
C , , , , , . #, , , .
, string.Format , ( ) - #. , , .
string.Format
, , , . , , , . .
, , .
, - :
string format = "{0}"; List<string> parms = new List<string> { "Hello" }; if (DateTime.Now.Second % 2 == 0) { format += " {1}"; parms.Add("World"); } Console.WriteLine(format, parms.ToArray());
Resharper : " ".
"format" . , , .
, ... (!)
.
: . , , . , : .
, String.Format(, , ), ... .