views:

138

answers:

2

Hi, I do not understand why there is Control.padding.all which is int and according to hint there is set as well as get but I cannot set it (Control.Padding.All=5)? I would be grateful for explanation. Thanks!

+1  A: 

Control.Margin = new Padding(5)

Alex Reitbort
Yeah I know how to get it work..I just do not understand why there is Padding.all or left or whatever...but cannot be set as a int.
Petr
A: 

Here is a simple Implementation of this

public class ARAControl
{
    public ARAPadding Padding { get; set; }
}
public struct ARAPadding

{
    public int All { get; set; }
}

And if you use this you probably get this error

        ARAControl control = new ARAControl();
        control.Padding.All = 10;

It hapens because structure is a value type. By setting this property you first call get Method. Property Get will return a copy of Padding so it is a value type and C# will detect out mistake and prevent compiling

Ahmadreza
I've just submitted a post about this issue in my blog: http://ahmadreza.com/blog/post/Value-type-property-and-C-compilation-error.aspx
Ahmadreza