String.Format works fine with Debug.WriteLine if variable not of string type:
int myNumber = 1;
Debug.WriteLine("Put number here: {0}", myNumber);
Correct Output with Non-String
But if variable is string:
string myString = "ShouldWork";
Debug.WriteLine("Put text here: {0}", myString);
Incorrect Output with String
You are getting the wrong overload...
You could work around that:
Debug.WriteLine("Put text here: {0}", myString, null/*dummy*/);
A good wrapper would be
public static void DebugFormat(string fmt, params object[] p)
{
Debug.WriteLine(fmt, p); // this will select the right overload
// ... due to typeof(p)==object[]
}
// ...
DebugFormat("Put text here: {0}", myString, null/*dummy*/);
int myNumber = 1;
DebugFormat("Put number here: {0}", myNumber);
You are inadvertently calling a different overload:
http://msdn.microsoft.com/en-us/library/1w33ay0x.aspx
For the desired behavior, you can use string concatenation:
Debug.WriteLine("Put text here: " + myString);
or a call to String.Format:
Debug.WriteLine(String.Format ("Put text here: {0}", myString));
Try:
Debug.WriteLine(string.Format("Put number here: {0}", 1));
Also, make sure that your Output option (drop down menu) in Visual Studio is set to Debug... It is not on by default in many cases.
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