What are the original reasons for ToString() in Java and .NET?
Posted
by d.
on Stack Overflow
See other posts from Stack Overflow
or by d.
Published on 2010-02-21T23:26:05Z
Indexed on
2010/05/18
2:10 UTC
Read the original article
Hit count: 220
I've used ToString()
modestly in the past and I've found it very useful in many circumstances. However, my usage of this method would hardly justify to put this method in none other than System.Object
. My wild guess is that, at some point during the work carried out and meetings held to come up with the initial design of the .NET framework, it was decided that it was necessary - or at least extremely useful - to include a ToString()
method that would be implemented by everything in the .NET framework.
Does anyone know what the exact reasons were? Am I missing a ton of situations where ToString()
proves useful enough as to be part of System.Object
? What were the original reasons for ToString()
?
Thanks a lot!
PS - Again: I'm not questioning the method or implying that it's not useful, I'm just curious to know what makes it SO useful as to be placed in System.Object
.
Side note - Imagine this:
AnyDotNetNativeClass someInitialObject = new AnyDotNetNativeClass([some constructor parameters]);
AnyDotNetNativeClass initialObjectFullCopy = AnyDotNetNativeClass.FromString(someInitialObject.ToString());
Wouldn't this be cool?
EDIT(1):
(A) - Based on some answers, it seems that .NET languages inherited this from Java. So, I'm adding "Java" to the subject and to the tags as well. If someone knows the reasons why this was implemented in Java then please shed some light!
(B) - Static hypothetical FromString
vs Serialization: sure, but that's quite a different story, right?
© Stack Overflow or respective owner