gpt4 book ai didi

c# - Debug.WriteLine 重载似乎有冲突

转载 作者:太空狗 更新时间:2023-10-29 20:04:50 25 4
gpt4 key购买 nike

在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com