Is there a built in function in C# / .net that will take a variable and describe / output it’s contents? In PHP there are the print_r() and var_dump() functions which achieve this (I realise the inherent difference between C# and PHP, just providing a example of output)
As this is for a logging script it needs to be as lightweight and unintrusive as possible – I’m considering writing a function to do this however would prefer to use a built in if available.
Examples of variables would be arrays / lists of custom objects, dumping out of eventargs passed to an event handler etc. I’d like to take this as far as possible whilst avoiding the expense of reflection.
Thanks
See my answer to this question for a summary of different ways to get a string representation of an object:
String casts
Since you want this to be both very generic and lightweight your best option here is probably
Convert.ToString().