Hallo
Ich habe eine Frage: und zwar kann man eine Methode (zum Beispiel toString()) einer Klasse aus einer Property, die auf ein Feld dieser Klasse verweist, überschreiben?
Um das Jetzt mal zu veranschaulichen ein bischen Code:
ich will dass wenn jemand MyClassObject.MyBool.toString() aufruft er nicht die standard toString funktion aurruft sondern meine, und dazu möchte ich nicht eine klasse erstellen die von Bool oder Boolean erbt.
ich hab mir das ca so vorgestellt:
gibt es etwas in diese richtung?
Ich habe eine Frage: und zwar kann man eine Methode (zum Beispiel toString()) einer Klasse aus einer Property, die auf ein Feld dieser Klasse verweist, überschreiben?
Um das Jetzt mal zu veranschaulichen ein bischen Code:
Code:
pulbic class MyClass { private bool myBool; public bool MyBool { get{return myBool;} set{mybool = value;} } }
ich will dass wenn jemand MyClassObject.MyBool.toString() aufruft er nicht die standard toString funktion aurruft sondern meine, und dazu möchte ich nicht eine klasse erstellen die von Bool oder Boolean erbt.
ich hab mir das ca so vorgestellt:
Code:
pulbic class MyClass { private bool myBool; public bool MyBool { get{return myBool;} set{mybool = value;} toString{return myBool?"ja":"nein"} } }
gibt es etwas in diese richtung?
Comment