Canonical Console.WriteLine in LinqPad

╄→尐↘猪︶ㄣ 提交于 2019-12-23 06:50:20

问题


Linqpad's souped-up Console.WriteLine is awesome. However, how can I do a standard Console.WriteLine of an object?


回答1:


Debug.WriteLine will also do the trick.




回答2:


Huh, obvious now - put in an explicit ToString

Console.WriteLine(x.ToString());



回答3:


You can also add these methods to your "MyExtensions" file in the "My Queries" pane. This way you can use .DumpToString instead of .Dump. Maybe they should be renamed 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);
}



回答4:


You can also do

x.Dump();

Which will use the LinqPad API to pretty format the output.



来源:https://stackoverflow.com/questions/12726207/canonical-console-writeline-in-linqpad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!