Click here to Skip to main content
15,891,567 members
Home / Discussions / C#
   

C#

 
GeneralRe: string and array are immutable? [Modified] Pin
George_George25-Aug-08 1:28
George_George25-Aug-08 1:28 
GeneralRe: string and array are immutable? [Modified] Pin
N a v a n e e t h25-Aug-08 1:35
N a v a n e e t h25-Aug-08 1:35 
GeneralRe: string and array are immutable? [Modified] Pin
George_George25-Aug-08 1:39
George_George25-Aug-08 1:39 
GeneralRe: string and array are immutable? [Modified] Pin
N a v a n e e t h25-Aug-08 1:30
N a v a n e e t h25-Aug-08 1:30 
GeneralRe: string and array are immutable? [Modified] Pin
George_George25-Aug-08 1:33
George_George25-Aug-08 1:33 
GeneralRe: string and array are immutable? [Modified] Pin
N a v a n e e t h25-Aug-08 1:39
N a v a n e e t h25-Aug-08 1:39 
GeneralRe: string and array are immutable? [Modified] Pin
George_George25-Aug-08 1:42
George_George25-Aug-08 1:42 
GeneralRe: string and array are immutable? [Modified] Pin
Mustafa Ismail Mustafa25-Aug-08 2:44
Mustafa Ismail Mustafa25-Aug-08 2:44 
N a v a n e e t h wrote:
I doubt this. Array is a block of data with some length and provides indexer to access the data. This is correct for strings. But AFAIK, strings are stored as inline not as character array. Correct me if I am wrong.


A string is a sequential collection of Unicode characters that is used to represent text. A String object is a sequential collection of System.Char objects that represent a string. The value of the String object is the content of the sequential collection, and that value is immutable.

A String object is called immutable (read-only) because its value cannot be modified once it has been created. Methods that appear to modify a String object actually return a new String object that contains the modification. If it is necessary to modify the actual contents of a string-like object, use the System.Text.StringBuilder class.
(source: http://msdn.microsoft.com/en-us/library/system.string.aspx[^])

An Array by definition is a sequential collection of the same data type accessed through an indexer (offset). So it seems like it. Also, It appears that (specifically with strings) even if you try to alter the contents, a new string is actually returned.



N a v a n e e t h wrote:
MS just wrapped the array copying logic inside these classes. When additional space required, a new array will be created and existing contents will be copied to there.


I can't find any sources for or against this argument, but from what I know and remember, all these collection objects are based on the original ArrayList which inherits directly from the System.Object, whilst all the other ValueTypes inherit from System.ValueType, so I'd guess they're different. Also, aren't arrays pushed onto the stack whilst the other dynamic datastructures get pushed onto the heap? I'm not too sure, so don't consider my arguments as final. Indeed, this is becoming something I'm interested in finding out.

Don't forget to vote if the response was helpful


Sig history

"dad" Ishmail-Samuel Mustafa

"There's no point questioning the actions of a c0ck-juggling thunderc*nt" From the book of testy commentary by martin_hughes

Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation

GeneralRe: string and array are immutable? [Modified] Pin
N a v a n e e t h25-Aug-08 7:00
N a v a n e e t h25-Aug-08 7:00 
GeneralRe: string and array are immutable? [Modified] Pin
Mustafa Ismail Mustafa25-Aug-08 9:13
Mustafa Ismail Mustafa25-Aug-08 9:13 
GeneralRe: string and array are immutable? [Modified] Pin
N a v a n e e t h25-Aug-08 18:23
N a v a n e e t h25-Aug-08 18:23 
AnswerRe: string and array are immutable? Pin
AhsanS25-Aug-08 1:12
AhsanS25-Aug-08 1:12 
GeneralRe: string and array are immutable? Pin
George_George25-Aug-08 1:30
George_George25-Aug-08 1:30 
QuestionCreate a full screen C# program... Pin
Hirakawa24-Aug-08 23:33
Hirakawa24-Aug-08 23:33 
AnswerRe: Create a full screen C# program... Pin
AhsanS25-Aug-08 1:14
AhsanS25-Aug-08 1:14 
GeneralRe: Create a full screen C# program... Pin
chaiguy133725-Aug-08 15:14
chaiguy133725-Aug-08 15:14 
AnswerRe: Create a full screen C# program... Pin
Manas Bhardwaj25-Aug-08 1:28
professionalManas Bhardwaj25-Aug-08 1:28 
AnswerRe: Create a full screen C# program... Pin
Hirakawa25-Aug-08 15:13
Hirakawa25-Aug-08 15:13 
GeneralRe: Create a full screen C# program... Pin
Manas Bhardwaj25-Aug-08 20:48
professionalManas Bhardwaj25-Aug-08 20:48 
QuestionHelp me resolve problem! Pin
medop8224-Aug-08 23:31
medop8224-Aug-08 23:31 
AnswerRe: Help me resolve problem! Pin
N a v a n e e t h24-Aug-08 23:44
N a v a n e e t h24-Aug-08 23:44 
JokeRe: Help me resolve problem! Pin
lisan_al_ghaib25-Aug-08 0:14
lisan_al_ghaib25-Aug-08 0:14 
AnswerRe: Help me resolve problem! Pin
Guffa25-Aug-08 1:43
Guffa25-Aug-08 1:43 
GeneralRe: Help me resolve problem! Pin
chaiguy133725-Aug-08 15:18
chaiguy133725-Aug-08 15:18 
QuestionHow to convert a structure data into bytes Pin
kk.tvm24-Aug-08 22:54
kk.tvm24-Aug-08 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.