[問題] 陣列大小的問題

看板C_Sharp (C#)作者 (這就是人生嗎)時間15年前 (2010/01/25 14:30), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/2 (看更多)
剛剛按照msdn建了一段程式碼 http://msdn.microsoft.com/zh-tw/library/ms171731(VS.80).aspx namespace SerializationDemoControlLib { public partial class SerializationDemoControl : UserControl { private String[] stringsValue = new String[1]; public SerializationDemoControl() { InitializeComponent(); } [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public String[] Strings { get { return this.stringsValue; } set { this.stringsValue = value; // Populate the contained TextBox with the values // in the stringsValue array. StringBuilder sb = new StringBuilder(this.stringsValue.Length); for (int i = 0; i < this.stringsValue.Length; i++) { sb.Append(this.stringsValue[i]); sb.Append("\r\n"); } this.textBox1.Text = sb.ToString(); } } } } ================================================================ 我的問題是,一開始宣告 private String[] stringsValue = new String[1]; 不就已經指定大小為 1 嗎 為什麼到後來還可以改變呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.120.103.217

01/25 18:14, , 1F
啊你在this.stringsValue = value;就改掉了呀
01/25 18:14, 1F

01/25 18:15, , 2F
你把他指到別的東西去了,原來的string[1]被你丟到一邊去了
01/25 18:15, 2F

01/25 20:55, , 3F
XD 對喔 我在搞什麼@@
01/25 20:55, 3F
文章代碼(AID): #1BNJfqJ6 (C_Sharp)
文章代碼(AID): #1BNJfqJ6 (C_Sharp)