Is a string actually a character array (is-a), or does it have a character array as an internal store (has-a), or is it's own object which can expose itself as a with an array of characters?
I am more inclined to say it is it's own object, but then why are we so inclined to always say "A string is an array of characters..."?
the .NET string is not just an array of characters. It contains an array of characters, so strictly speaking, it's has-a.
Moreover, there are a lot of Unicode-related subtleties where it doesn't behave anything like an array. Concatenating a character may do a lot more than just increase the string length by one, and insert the new character at the end. According to the Unicode normalization rules, it may actually change the entire string. So it is definitely nothing like an array of characters, but somewhere within the class, such an array exists.
It depends on your definition of the word "string".
System.String
type in .NET has a character array as internal store (it also stores length (which is O(1)), among other things, for example).
But the word string means a consecutive occurrence of something in general, which might also mean a character array :))
By the way, when I said string
type has a "character array," I didn't mean "a field of type char[]
" specifically. I meant the general meaning of the term "array" as an ordered collection of something. :))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With