abelenky abelenky - 2 months ago 6
C# Question

Debug.WriteLine overloads seem to conflict

In C#.Net,

System.Diagnostics.Debug.WriteLine
has several overloads, including these two:

//http://msdn.microsoft.com/en-us/library/cc190153.aspx
public static void WriteLine(string format, params Object[] args);

//http://msdn.microsoft.com/en-us/library/1w33ay0x.aspx
public static void WriteLine(string message, string category);


My intention is to call the first one with:

Debug.WriteLine("The path is {0}", myObj.myPath);


But it appears that I'm actually calling the second overload, because it is a more exact match.

Is there a simple way to indicate that I want the first one?

My best attempts so far are:

Debug.WriteLine("The path is {0}", new object[]{myObj.myPath});
Debug.WriteLine("The path is {0}", myObj.myPath, "");


But neither of these looks very elegant.

Answer

Try this:

Debug.WriteLine("The path is {0}", (object)myObj.myPath);
Comments