CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 19

Threaded View

  1. #16
    Join Date
    Mar 2007
    Posts
    155

    Re: string in Stack or Heap ?

    Quote Originally Posted by BigEd781 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured