2009-11-26 61 views

回答

1

下面是這種

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

{ 
    public int All { get; set; } 
} 

一個簡單的實現,並且如果你使用這個,你可能得到這個錯誤

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

它hapens因爲結構是一種價值類型。通過設置這個屬性,你首先調用get方法。 Get屬性將返回填充的副本,所以它是一個價值型和C#將檢測出的錯誤,並防止編譯

+0

我剛剛在我的博客中提交了有關此問題的帖子:http://ahmadreza.com/blog/post/Value-type-property-and-C-compilation-error.aspx – Ahmadreza 2009-12-10 21:34:58

4

Control.Margin =新的填充(5)

+0

是的,我知道如何得到它work..I只是不明白爲什麼有Padding.all或左或無論...但不能設置爲int。 – Petr 2009-11-26 08:19:11

+0

也不是!對於爲什麼可能不分配這個int的答案,我也會很生氣。 – ChrisJJ 2011-09-21 17:53:56

相關問題