Click here to Skip to main content
13,055,047 members (53,116 online)
Click here to Skip to main content
Articles » Languages » C# » General » Alternatives
Alternatives (2)
Add your own
alternative version

Tagged as

Stats

30.2K views
9 bookmarked
Posted 2 Sep 2011

Useful wrapper class to override the Object.ToString method

, 3 Oct 2011
A useful wrapper class to override the Object.ToString method.

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

4 Oct 2011
kct
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));
4 Oct 2011
smilewei
You can write an extension method like this:public static class ToStringExtensionMethod{ public static string ToString(this Person person, bool showName) { return person.Name; }}then you can use it like this:public class Program{ Person person = new...

License

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

Share

About the Author

Jay_Cee
South Africa South Africa
No Biography provided

Pro
| | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 3 Oct 2011
Article Copyright 2011 by Jay_Cee
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid