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

, 4 Oct 2011
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 | Mobile
Web01 | 2.8.140721.1 | Last Updated 4 Oct 2011
Article Copyright 2011 by kct
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid