Modifying nested structs in c#
- by joniba
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);
}
}