|
-
July 29th, 2009, 10:38 PM
#16
Re: string in Stack or Heap ?
 Originally Posted by BigEd781
No, it is immutable simply because the class gives you no way to change its member data. Look at this class:
Code:
class Foo
{
public readonly int Id;
public readonly string Name;
public Foo( int id, string name )
{
Id = id;
Name = name;
}
}
That class is immutable. You pass some data into the constructor, the data is set, and now there is no way that it can be changed by the outside world.
Brilliant. Very nice example.
So all of it's member must be const/readonly. And string might have internally implemented similiar pattern. Am I right ?
Last edited by thomus07; July 29th, 2009 at 10:50 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|