的代码在我的类的构造函数下面的行抛出一个StackOverflowException:为什么我的数组初始化代码会导致抛出StackOverflowException?
myList = new string[]{}; // myList is a property of type string[]
这是为什么发生?什么是初始化空数组的正确方法?
UPDATE:的原因是在设定器,其中我试图将修剪的所有值:
set
{
for (int i = 0; i < myList.Length; i++)
{
if (myList[i] != null) myList[i] = myList[i].Trim();
}
}
你能发布你的构造函数吗?看起来问题的真正原因可能在另一条线上。 – Syntactic 2010-05-26 17:17:04