在 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);

我的目的是调用第一个:
Debug.WriteLine("The path is {0}", myObj.myPath);

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

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

到目前为止,我最好的尝试是:
Debug.WriteLine("The path is {0}", new object[]{myObj.myPath});
Debug.WriteLine("The path is {0}", myObj.myPath, "");

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

最佳答案

试试这个:

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

关于c# - Debug.WriteLine 重载似乎冲突,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18190388/

10-12 21:09