Debug.WriteLine重载似乎冲突

abe*_*nky 7 .net c# overloading

在C#.Net中,System.Diagnostics.Debug.WriteLine有几个重载,包括这两个:

//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);
Run Code Online (Sandbox Code Playgroud)

我的意图是打电话给第一个:

Debug.WriteLine("The path is {0}", myObj.myPath);
Run Code Online (Sandbox Code Playgroud)

但看起来我实际上是在调用第二个重载,因为它是一个更精确的匹配.

有没有一种简单的方法来表明我想要第一个?

到目前为止,我最好的尝试是:

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

但这些看起来都不是很优雅.

Dan*_*rth 6

试试这个:

Debug.WriteLine("The path is {0}", (object)myObj.myPath);
Run Code Online (Sandbox Code Playgroud)