Empty accessors do matter? Regarding value types and their modification

Posted by Petr on Stack Overflow See other posts from Stack Overflow or by Petr
Published on 2010-04-07T08:31:32Z Indexed on 2010/04/07 8:43 UTC
Read the original article Hit count: 351

Filed under:
|
|

Hi, I have following code that does not work due to "a" being a value typed. But I thought it would not work even without accessors, but it did:

class Program
    {
        a _a  //with accessors it WONT compile
        {
            get; 
            set;
        }
        static void Main(string[] args)
        {
            Program p = new Program();
            p._a.X = 5; //when both accessors are deleted, compiler does not
                        //complain about _a.X not being as variable
        }
    }
    struct a
    {
       public int X;
    }

It does not work as "a" is struct. But when I delete accessors from "_a" instance, it works. I do not understand why. Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about accessors