c# - Debug.WriteLine() 与 Console.WriteLine() 处理文化的方式不同。为什么?

标签 c# .net culture date-formatting

考虑以下控制台应用程序代码:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

DateTime date = new DateTime(2014, 01, 19);

Console.WriteLine("{0}", date); // Prints 19/01/2014
Debug.WriteLine("{0}", date);   // Prints 01/19/2014
Debug.WriteLine(date);          // Prints 19/01/2014

如评论中所述,Console.WriteLine() 打印 19/01/2014Debug.WriteLine() 打印01/19/2014

更糟糕的是 - Debug.WriteLine("{0}", date) 给出了与 Debug.WriteLine(date) 不同的输出...

Debug.WriteLine() 是否会忽略线程的文化设置?

有没有办法让 Debug.WriteLine() 使用线程的文化设置?还是我必须使用 String.Format() 并将结果传递给 Debug.WriteLine()

(注意:我在 Windows 8.1 64 位 en-GB 上运行此程序,使用带有 .Net 4.51 的 Visual Studio 2013 和调试 AnyCPU 构建。)

最佳答案

这是明确处理的in the source .

这也是有道理的。
调试输出不应受到最终用户文化的影响;无论代码在何处运行,您都希望调试日志保持一致。

关于c# - Debug.WriteLine() 与 Console.WriteLine() 处理文化的方式不同。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28028128/

相关文章:

c# - Oracle 根据浏览器文化返回日期时间格式

c# - Form_Closed 是删除事件处理程序的正确位置吗?

c# - 求一个Winforms System.ComponentModel.Design Design Surface BeginDrag/EndDrag事件钩子(Hook)

.net - 如何在 WPF 应用程序 (Windows XP) 中全局设置区域性?

.net - 如何在 XElement 上设置 namespace 属性

.net - 在 winforms 应用程序中使用 ASP.NET 成员资格提供程序是个坏主意吗?

.net - 是否有可能使日期数据类型接受一个月的13和所有月份的30?

c# - 在 dynamodb 中使用 context.fromquery 查询时限制不起作用

c# - 启动和停止服务

c# - 列表输出 namespace 的名称,而不是其值