Modifying nested structs in c#

Posted by joniba on Stack Overflow See other posts from Stack Overflow or by joniba
Published on 2010-04-12T16:44:48Z Indexed on 2010/04/12 16:53 UTC
Read the original article Hit count: 561

Filed under:
|

Can someone tell me why the commented line of code (one before last) does not compile? Isn't it the same as the line following it?

public struct OtherStruct
{
    public int PublicProperty { get; set; }
    public int PublicField;

    public OtherStruct(int propertyValue, int fieldValue)
        : this()
    {
        PublicProperty = propertyValue;
        PublicField = fieldValue;
    }

    public int GetProperty()
    {
        return PublicProperty;
    }
    public void SetProperty(int value)
    {
        PublicProperty = value;
    }
}

public struct SomeStruct
{
    public OtherStruct OtherStruct { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        SomeStruct a = new SomeStruct();
        //a.OtherStruct.PublicProperty++;
        a.OtherStruct.SetProperty(a.OtherStruct.GetProperty() + 1);
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about structs