I have the following Debug.WriteLine
:
Debug.WriteLine("Metadata Version: {0}", version); // update: version is a string
The output is:
2.0: Metadata Version: {0}
Why is the string formatted this way?
I didn't see anything in MSDN documentation that identifies reasoning behind this format. I have to do the following to get a correctly formatted output:
Debug.WriteLine(string.Format("Metadata Version: {0}", version));
Definition. Writes information about the debug to the trace listeners in the Listeners collection.
Debug. WriteLine writes to the debug output. You can see it in your debugger and save it from there.
Diagnostics. Debug. WriteLine will display in the output window ( Ctrl + Alt + O ), you can also add a TraceListener to the Debug.
Since version
is a string
, you're hitting the overload of WriteLine
that accepts a category as its second parameter.
While there are any number of hacks to get around this behavior (I'll include a few below, for fun) I would personally prefer your solution as the preferable way of clearly ensuring that the string is treated as a format string.
Some other hacky workarounds:
Debug.WriteLine("Metadata Version: {0}", version, ""); Debug.WriteLine("Metadata Version: {0}", (object)version); Debug.WriteLine("Metadata Version: {0}", new[] { version }); Debug.WriteLine("Metadata Version: {0}", version, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With