我知道結構是值類型,但我不明白爲什麼這個工程:
編輯:我的意思是,爲什麼this.Size.Height不起作用呢?C#-2結構問題
struct A
{
int height;
public int Height
{
get
{
return height;
}
set
{
height = value;
}
}
}
//... class Main
{
A a = A();
a.Height = 5; //works. Why? I thought it should say "cannot modify as it is not variable". I think the properties should return copy of this struct...?
}
第二個問題 - 我看過,我不需要用「新」與結構,但它不沒有它爲我工作。
未來如果您有兩個問題,請考慮發佈*兩個*問題,而不是將它們組合成一個問題。這樣每個問題都有一組明確的答案。 – 2010-06-19 14:51:46