Object Properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Bean

    #1

    Object Properties

    Can someone confirm if member object variable are set directly they are
    stored as copys of the object but if they are set using a property they are
    stored as references?

    For example, in the code below:

    Does the statement "textBox1 = textBox0;" make a copy of textBox0 and assign
    it to textBox0?

    Does the statement "TextBoxPropert y = textBox0" store a reference to
    textBox0 in textBox1?

    public class MyClass
    {
    public TextBox textBox1;
    ...
    public TextBox TextBoxProperty
    {
    set
    {
    textBox1 = value;
    }
    }
    }


  • Jon Skeet

    #2
    Re: Object Properties

    Tom Bean <tbean@t-a-c.com> wrote:[color=blue]
    > Can someone confirm if member object variable are set directly they are
    > stored as copys of the object but if they are set using a property they are
    > stored as references?[/color]

    No, that's not true at all. Reference types always use references to
    objects, value types always use straight object values. See
    http://www.pobox.com/~skeet/csharp/parameters.html for more
    information.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Tom Bean

      #3
      Re: Object Properties

      Jon,

      So, no matter how the member object variable is assigned it is always stored
      as a reference?

      Tom

      "Jon Skeet" <skeet@pobox.co m> wrote in message
      news:MPG.198397 b8e747d02f98a16 9@news.microsof t.com...[color=blue]
      > Tom Bean <tbean@t-a-c.com> wrote:[color=green]
      > > Can someone confirm if member object variable are set directly they are
      > > stored as copys of the object but if they are set using a property they[/color][/color]
      are[color=blue][color=green]
      > > stored as references?[/color]
      >
      > No, that's not true at all. Reference types always use references to
      > objects, value types always use straight object values. See
      > http://www.pobox.com/~skeet/csharp/parameters.html for more
      > information.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet/
      > If replying to the group, please do not mail me too[/color]


      Comment

      Working...