c# - 在 LINQPad 中使用 Dump() 扩展方法和使用 Console.WriteLine() 有什么区别?

标签 c# linq dump linqpad

当我观看有关 Csharp async 和 wait 概念的教程视频时,我第一次遇到 Dump() 方法。讲师使用此方法如下:

public string BoilWater()
{
"Start the kettle".Dump();
"Waiting for the kettle".Dump();
"Kettle finished boiling".Dump():
return water;
}

这是此代码的输出:

Start the kettle
Waiting for the kettle
Kettle finished boiling

虽然我是 Csharp 的新手,但通过阅读《Programming C# 5.0》一书,我已经对 LINQ 有了一些了解,并且我也使用过 LINQPad。我已经对此进行了一些搜索,但说实话,我找不到太多有关 Dump() 方法的信息。 所以,这是我的问题,我们可以使用 Console.WriteLine 来创建此输出吗?在这里使用 Dump() 相对于 Console.WriteLine 有什么优势?

最佳答案

这就是 LINQPad关于转储说:

LINQPad’s Dump method is famous for its capacity to eat almost anything!

Tuned with numerous heuristics, it intelligently walks object graphs for the best possible output. It even turns lazy objects into hyperlinks and asynchronous values into placeholders whose content materializes in the future!

Images and bitmaps render as images and bitmaps, and types from Reactive Extensions and Dataflow fully animate.

Dump any WPF or Windows Forms object and it will actually render.

And when you need a traditional data grid or debugger watch window, it’s there, too.

因此,Dump() 是一个非常有用的扩展,它将帮助我们调试和理解代码的工作原理,或者我们可以获得哪些信息。 Dump() 使用 LINQPad 的输出格式化程序写入输出窗口,并被重载以让我们指定标题并指定最大递归深度以覆盖默认的 5 级。

typeof (int).Assembly.Dump ("heading");
typeof (int).Assembly.Dump ("number of level we want to dump deep"); 

令人惊讶的是,该方法有几个可用的参数,例如描述、深度、toDataGrid 和排除,这使得使用 Dump 变得更加有趣。在此堆栈溢出页面中对它们进行了更多描述:here

关于c# - 在 LINQPad 中使用 Dump() 扩展方法和使用 Console.WriteLine() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64672727/

相关文章:

c# - HttpClientFactory 任务取消异常 : Unable to read data from the transport connection

c# - 强制使用自定义属性

c# - 按列表中的子属性排序

.net - FirstOrDefault()、SingleOrDefault()、Any() 等...哪一个最快?

asp.net - LINQ 问题 : FK-Table not set correctly

PostgreSQL 转储临时表

c# - 按 id 从 mongodb 2.4 版的子文档中删除

c# - 如果我的传入日期格式为 YYYYMMDD,则在 .NET 中将字符串转换为日期

java - 如何设置 tanuki 包装器的 java 转储文件位置

c# - 是否可以将 DLL 从进程内存导出/转储到文件?