How to override? ToString()
textBox1.Text.**ToString()**
How to override? ToString()
textBox1.Text.**ToString()**
To do that you'll need to create a new TextBox that inherits from TextBox and overrides ToString. Have a read here for more info:
How To Override the ToString Method (MSDN)
There may be better ways to do accomplish what you're trying to do though that will be easier to implement if you can specify more details
Well, to overload the Text property you'd have to inherit from TextBox yourself, which I doubt you want to do
An easier solution would be creating an extension method for string to do what you want:
public static class StringExtensions
{
ToSpecialString(this string)
{
//do your special ToString() here
}
}
We are both override :
class Class1:TextBox
{
public Class1()
{
// this.Text.ToString();
}
public override string ToString()
{
return ("mystring");
}
//protected override Text.tostrong()
//{
//}
}
Why on earth would you want to? Text is already a string.
If you need to format the string differently, use String.Format(...), or a custom method you don't need to override the behavior.