I have a List<object>. I want to loop over the list and print the values out in a more friendly manner than just o.ToString() in case some of the objects are booleans, or datetimes, etc.
How would you structure a function that I can call like MyToString(o) and return a string formatted correctly (specified by me) for its actual type?
You can use the dynamic keyword for this with .NET 4.0, since you’re dealing with built in types. Otherwise, you’d use polymorphism for this.
Example:
Prints out: