[英]How to Console.Log, Print_R(), Debug.Trace in C#?
PHP has a function called print_r() and var_dump() that will display all the contents of an item. PHP有一个名为print_r()和var_dump()的函数,它将显示项目的所有内容。 It makes it very easy to figure out what things are.
它可以很容易地弄清楚它是什么。
Is there something like that in C#? C#中有类似的东西吗?
I know there is a Console.WriteLine("Hello");
我知道有一个
Console.WriteLine("Hello");
in C#, but does this work in the MVC? 在C#中,但这在MVC中有效吗? Can I do some type of
debug.trace()
like flash does into a debug console while I run the application? 在运行应用程序时,我可以将某些类型的
debug.trace()
像flash一样进入调试控制台吗?
System.Diagnostics.Debug.WriteLine("blah");
and in order to show all variables in the object you would have to override its ToString() method or write a method which returns all the info you need from the object. 并且为了显示对象中的所有变量,您必须覆盖其ToString()方法或编写一个返回对象所需的所有信息的方法。 ie
即
class Blah{
string mol = "The meaning of life is";
int a = 42;
public override string ToString()
{
return String.Format("{0} {1}", mol, a);
}
}
System.Diagnostics.Debug.WriteLine(new Blah().ToString());
In short there is nothing in built but it can be done. 简而言之,没有任何内置,但它可以做到。
If you must print ALL the objects info without overriding or adding logic on a class by class level then you are in the realms of reflection to iterate the objects PropertInfo array 如果必须打印所有对象信息而不在类级别上覆盖或添加逻辑,那么您在反射领域中迭代对象PropertInfo数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.