ASP.NET equivalent to PHP function Print_r?

PHP Print_r is useful for printing an array and a collection of dictionaries. is it asp.net build in this function?

+3
source share
6 answers

What you are looking for is called "beautiful print." Google ".NET pprint", maybe you're in luck.

But really, use a debugger.

-1
source

You can achieve this with JavaScriptSerializer

var json = new JavaScriptSerializer().Serialize(yourObject);
Response.Write("yourObject:" + json + "<br/>");
+2
source

framework. . ToString . XML, .

+1
source

As others have said: you can use the debugger to get a better overview if that is what you need. If you want to show the data in html, you can bind the object to the control, which is a much more powerful and flexible way to handle the output.

+1
source

There is no function available in .net as print_r (). But in response, you can use your custom function and print array or IEnumerable. For example,

if (val is IEnumerable)
        {
            var e = val as IEnumerable;
            foreach (var i in e)
            {
                Response.Write(i.ToString() + "<br />");
            }
        }
+1
source

You may try:

string[] weekDays4 = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
foreach (var item in weekDays4)
{
  Response.Write(item.ToString() + " test<br />");
}
0
source

Source: https://habr.com/ru/post/1706645/


All Articles