C# in VS2005: can you overload the .ToString()
method of a property?
views:
55answers:
1
+5
A:
No - properties have a get
method, which returns a value -- you can overload the implementation of ToString()
on the type of that value, which will allow you to do:
myClass.MyProperty.ToString()
which is likely what you're looking for. Simply define a function such as:
public override string ToString() {
// return string version of value
}
in that type's class.
Blair Holloway
2010-07-19 03:39:56
That is unfortunate. A Property is like a wrapper object for a type, so I think you should be able to overload methods like ToString() to customise the string representation of a Property.
Craig Johnston
2010-07-20 07:39:38