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

Useful wrapper class to override the Object.ToString method

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

License

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

About the Author

kct

Germany Germany
No Biography provided

Comments and Discussions

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