Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Useful wrapper class to override the Object.ToString method

, 4 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Here with generics:public static string ToString(this T obj, Func toStringFunction) { return toStringFunction(obj); }You can use it like this:Console.WriteLine(person.ToString(p=>p.Name));
Here with generics:
public static string ToString<T>(this T obj, Func<T, string> toStringFunction)
         return toStringFunction(obj);
You can use it like this:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author


Germany Germany
No Biography provided

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150331.1 | Last Updated 4 Oct 2011
Article Copyright 2011 by kct
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid