Setting Padding - why it says padding.all is not variable?
I do not understand why there is Control.padding.all which is int and according to hint there is set as well as get b开发者_StackOverflow中文版ut I cannot set it (Control.Padding.All=5)? I would be grateful for explanation. Thanks!
Control.Margin = new Padding(5)
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
精彩评论