useless...
-
txtName being a text field: txtName.Text.ToString() X|
Noman Muhammad Aftab, Software Mechanic
-
txtName being a text field: txtName.Text.ToString() X|
Noman Muhammad Aftab, Software Mechanic
-
txtName being a text field: txtName.Text.ToString() X|
Noman Muhammad Aftab, Software Mechanic
-
I can't tell you how many times ive seen ToString() called on a string type. Its a typical newbie mistake, the lack of understanding of data types.
I wonder if the person is trying to be paranoid-protective about the possibility that a property might return a type which is not a string, but features bidirectional widening conversions? As a hypothetical example, one might have a private string-interning pool. Properties of a class which would normally return string could instead return items from the pool. If the properties returned strings, then setting one such property to another would require generating a new string object and then doing some sort of dictionary lookup to locate the string in the pool. By contrast, if the objects returned intern-pool references, those steps could be eliminated. One hazard with such an approach is that if such an object were passed to a function that expected something of type object, things would appear to work normally (the string would be extracted when the object was cast to a string) but the object that was kept would be a pool reference. This could cause an entire pool of interned strings to be kept alive even if there were no live references to anything that cared about the pool being a pool (just a reference to something thought to be a string).
-
I wonder if the person is trying to be paranoid-protective about the possibility that a property might return a type which is not a string, but features bidirectional widening conversions? As a hypothetical example, one might have a private string-interning pool. Properties of a class which would normally return string could instead return items from the pool. If the properties returned strings, then setting one such property to another would require generating a new string object and then doing some sort of dictionary lookup to locate the string in the pool. By contrast, if the objects returned intern-pool references, those steps could be eliminated. One hazard with such an approach is that if such an object were passed to a function that expected something of type object, things would appear to work normally (the string would be extracted when the object was cast to a string) but the object that was kept would be a pool reference. This could cause an entire pool of interned strings to be kept alive even if there were no live references to anything that cared about the pool being a pool (just a reference to something thought to be a string).
-
The sort of people who write
myTextField.Text.ToString()
would have no clue what you've just written.J4amieC wrote:
The sort of people who write myTextField.Text.ToString() would have no clue what you've just written.
Naturally. On the other hand, they might have heard of some vaguely-similar situation in which a competent programmer who did understand what was going on had applied some seemingly-unnecessary cast, and figured that if a cast was needed there and they didn't understand any distinction between that case and the one at hand, they should apply a cast (or explicit ToString) in the present case as well.
-
J4amieC wrote:
The sort of people who write myTextField.Text.ToString() would have no clue what you've just written.
Naturally. On the other hand, they might have heard of some vaguely-similar situation in which a competent programmer who did understand what was going on had applied some seemingly-unnecessary cast, and figured that if a cast was needed there and they didn't understand any distinction between that case and the one at hand, they should apply a cast (or explicit ToString) in the present case as well.
Now that reminds me of a time I had to maintain a (batch) program that accessed RDB. It had the equivalent of ToChar(ToChar(somestring)) all throughout the SQL code. The guy who had been maintaining it said it was that way when got it and that he was told it had to be that way. I called BS, removed the extraneous ToChar, and proved that it was unnecessary. I made some other changes and added some functionality and the resulting program ran in a quarter of the time.
-
I can't tell you how many times ive seen ToString() called on a string type. Its a typical newbie mistake, the lack of understanding of data types.
J4amieC wrote:
I can't tell you how many times ive seen ToString() called on a string type. Its a typical newbie mistake, the lack of understanding of data types.
To true. Great for catching newbies when conducting job interviews. Luckily though, the framework protects them from themselves:
// From mscorlib.dll
public override string ToString()
{
return this;
}Not perfect but at least there's not a whole redundant complex conversion of some kind taking place...
Before .NET 4.0, object Universe = NULL;