【发布时间】:2012-10-04 11:24:58
【问题描述】:
Linqpad 的增强版 Console.WriteLine 很棒。但是,我怎样才能做一个标准的 Console.WriteLine 对象呢?
【问题讨论】:
-
如果这个尊重
Consolecolors
标签: linqpad
Linqpad 的增强版 Console.WriteLine 很棒。但是,我怎样才能做一个标准的 Console.WriteLine 对象呢?
【问题讨论】:
Consolecolors
标签: linqpad
Debug.WriteLine 也可以解决问题。
【讨论】:
Consolecolors
嗯,现在很明显 - 放入显式 ToString
Console.WriteLine(x.ToString());
【讨论】:
您还可以将这些方法添加到“我的查询”窗格中的“我的扩展”文件中。这样您就可以使用 .DumpToString 而不是 .Dump。也许它们应该重命名为 DumpDebug ...
// Write custom extension methods here. They will be available to all queries.
public static void DumpToString<T>(this IEnumerable<T> list)
{
list.ToList().ForEach(x => Debug.WriteLine(x));
}
public static void DumpToString(this object o)
{
Debug.WriteLine(o);
}
public static void DumpToString(this string o)
{
Debug.WriteLine(o);
}
【讨论】:
你也可以这样做
x.Dump();
它将使用 LinqPad API 来漂亮地格式化输出。
【讨论】: