object

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

    object

    Hello!

    I have read this small example on some page on the internet but I can't
    understand
    how myValue can be a member of the x object.becaude object is a reserved key
    object.
    The same question is also valid how the y object can contain the member
    myValue?

    object x = new object();
    x.myValue = 10;
    object y = x;
    y.myValue = 20; // after this statement both x.myValue and y.myValue equal
    20


    //Tony


  • Jon Skeet [C# MVP]

    #2
    Re: object

    On Feb 18, 11:16 am, "TonyJ" <johansson.ande rs...@telia.com wrote:
    I have read this small example on some page on the internet but I can't
    understand how myValue can be a member of the x object.becaude
    object is a reserved key
    object.
    The same question is also valid how the y object can contain the member
    myValue?
    It can't - the code you gave isn't valid. Where did you get the sample
    from?

    Jon

    Comment

    • TonyJ

      #3
      Re: object

      Hello!

      In this place
      Discover the cutting-edge technology and expert services offered by CIS - Cyber Infrastructure, CIS, Learn more about our Company and our innovative digital solutions.


      //Tony

      "Jon Skeet [C# MVP]" <skeet@pobox.co mskrev i meddelandet
      news:eacc0166-dd63-46f8-baf4-8d920c651540@d5 g2000hsc.google groups.com...
      On Feb 18, 11:16 am, "TonyJ" <johansson.ande rs...@telia.com wrote:
      I have read this small example on some page on the internet but I can't
      understand how myValue can be a member of the x object.becaude
      object is a reserved key
      object.
      The same question is also valid how the y object can contain the member
      myValue?
      >
      It can't - the code you gave isn't valid. Where did you get the sample
      from?
      >
      Jon

      Comment

      • David Hearn

        #4
        Re: object

        Jon Skeet [C# MVP] wrote:
        TonyJ <johansson.ande rsson@telia.com wrote:>
        Right. It's probably worth dropping the author a mail to explain that
        his code is broken then :)
        >
        The actual article says:

        "Consider the following piece of code, in which two variables are given
        a reference to the same object (for the sake of the example, this object
        is taken to contain the numeric property 'myValue').

        object x = new object();
        x.myValue = 10;
        object y = x;
        y.myValue = 20; // after this statement both x.myValue and
        y.myValue equal 20"

        I guess, either the "for the sake of the example" (ie. this isn't valid
        in real life) bit was missed, or it has just been added following
        feedback from someone.

        D

        Comment

        Working...