Click here to Skip to main content
12,301,965 members (55,483 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

1.3K views
Posted

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:
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)

Share

About the Author

kct
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

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