When writing custom types, even if we do not writeTostringFunction, the system will also automatically provideTostringFunction, for example:
Public ClassClsuserinfo
{
Private StringStrusername;
......
}
However, the system providesTostringFunction, not doing too many things, and cannot truly reflect some attributes of the current object.Code, CallTostringReturned results andGetTypeConvertStringIs the same. The returned value does not have much meaning for the caller.
To provide a meaningfulTostringFunction, You need to reloadTostringFunction to implement an object-orientedTostringFunction. For exampleClsuserinfoThis type will makeTostringFunctions are more meaningful.
Public ClassClsuserinfo
{
Private StringStrusername;
......
Public Override StringTostring ()
{
Return String. Format ("User name: {0}", strusername );
}
}
Provide a meaningfulTostringFunctions are useful for debugging or publishing such a feature, because this method is the easiest way to combine strings with the member attributes of the feature class..However, when writing code, people, including me, tend to ignore providing a meaningfulTostringFunction, which seems to be improved in future encoding.
tostring C # iformattable interface, to provide more complex tostring functions, I don't want Because the interface is inherited, the tostring functions may change a lot. This can be realized only in real applications.