作者freewhat (这就是人生吗)
看板C_Sharp
标题[问题] 阵列大小的问题
时间Mon Jan 25 14:30:09 2010
刚刚按照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
1F:推 Elly:啊你在this.stringsValue = value;就改掉了呀 01/25 18:14
2F:→ Elly:你把他指到别的东西去了,原来的string[1]被你丢到一边去了 01/25 18:15
3F:→ freewhat:XD 对喔 我在搞什麽@@ 01/25 20:55