Re: Destructor: not gauranteed to be called?
- From: "Peter Oliphant" <poliphant@xxxxxxxxxxxxxxxx>
- Date: Thu, 2 Feb 2006 07:54:12 -0800
But, to the point. Can you think of a good justification as to why, no
matter what the contents of a Char[] are, that applying ToString to it
returns precisely this string and only this string every time:
"System.Char[]"?
Yes : coherence with all other arrays, see above...
Then you believe that ToString applied to an Int[] should return this string
and only this string every time:
"System.Int[]" (which maybe it does, I don't know)
Similarly, a Float[] should always return "System.Float[]" etc. Then why
doesn't applying ToString to just an Int return this string every time
"System.Int".? Seems a bit inconsistent to me. Why not just disallow
ToString from being applied to an array, instead of a constant response.
ToString has no valuable use for arrays anyway if that's all it does...
I guess we just have to agree to disgree on this. I personally don't feel a
function called ToString's purpose would be to return a string representing
the Type of any array and not be concerned at all with it's contents. I
feel it is incorrectly named when applied to arrays, and probably should
generate a compiler error when attempted (as has been mentioned ToString()
has nothing to do with any C++ standard, so MS can chose how to deal with
ToString() as they please).
ToString() does work as I would expect it on most entities: int's, floats's,
etc. This in a sense was part of the problem. It worked as I assumed it
would work in most cases, so it took a while to realize it wasn't doing what
I expected in the case of giving it a 'char'. As previously discussed,
ToString doesn't return a string with the single character passed to it, but
rather a string representing the decimal ASCII value of the char, for
example, '0'.ToString() = "48" since the ASCII value for the character '0'
is 48. MS claims this is proper. I don't feel the same way. I expected that
'0'.ToString() = "0". Silly me...
But I guess that's becuase I'm still thinking in 'C' terms. I still think of
a 'char' as a variable used to represent a symbolic member of the extended
alphabet ('a'-'z', 'A'-'Z', '0'-'9', etc.). Apparently this is old thinking.
The 'new hotness' is that a 'char' is just a byte with an ASCII value in it
Of course this means there is no natural way to convert a 'char' to a
String, or to insert one. Now that's progress... : )
[==P==]
"Arnaud Debaene" <adebaene@xxxxxxxxxxxxxxxx> wrote in message
news:uXiGlT8JGHA.2336@xxxxxxxxxxxxxxxxxxxxxxx
Peter Oliphant wrote:
- The fact yhat you require or expect a Char[] to act as a string is
a sign that you are still in a "C" way of though. In OOP, a string is
an object in itself, and an char array is just an array, it has
nothing to do with strings. The fact that in C, a string is a char[]
is a kludge that has no reason to be in OOP.
Maybe. I don't think I'm expecting Char[] to act like a string, but
believe the natural and expected result of applying ToString to it
would return a contatenation of the characters in order in the array
as one string
Ok, then go the end of your reasoning : If Char[].ToString should return
the concatentation of the chars, then Int[].ToString should return the
concatenation of the ints, Float[].ToString should return the
concatenation of the floats (totally meaningless), and
SomeObject[].ToString() should return the concatenation of SomeObjects
(probably totally meaningless too)....
But, to the point. Can you think of a good justification as to why, noYes : coherence with all other arrays, see above...
matter what the contents of a Char[] are, that applying ToString to it
returns precisely this string and only this string every time:
"System.Char[]"?
Arnaud
MVP - VC
.
- References:
- Re: Destructor: not gauranteed to be called?
- From: Arnaud Debaene
- Re: Destructor: not gauranteed to be called?
- From: Peter Oliphant
- Re: Destructor: not gauranteed to be called?
- From: Arnaud Debaene
- Re: Destructor: not gauranteed to be called?
- From: Peter Oliphant
- Re: Destructor: not gauranteed to be called?
- From: Arnaud Debaene
- Re: Destructor: not gauranteed to be called?
- Prev by Date: Re: Wrong type of char array
- Next by Date: Re: Destructor: not gauranteed to be called?
- Previous by thread: Re: Destructor: not gauranteed to be called?
- Next by thread: Re: Destructor: not gauranteed to be called?
- Index(es):
Relevant Pages
|