abelenky abelenky - 1 year ago 59
C# Question

Debug.WriteLine overloads seem to conflict

In C#.Net,

has several overloads, including these two:

public static void WriteLine(string format, params Object[] args);

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 Source

Try this:

Debug.WriteLine("The path is {0}", (object)myObj.myPath);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download