在下面的代码中,StylusPointCollection (SPC) 根据我是在方法内部还是外部声明 StylusPoint 变量而变化(即,如果我注释内部定义并取消注释注释行)。我不明白为什么会这样。
//StylusPoint spXY;
private void DrawBinaryTree(int depth, StylusPoint pt, double length, double theta)
{
if (depth > 0)
{
StylusPoint spXY = new StylusPoint(pt.X + length * Math.Cos(theta) * Math.Cos(a), pt.Y + length * Math.Sin(theta) * Math.Sin(a));
//spXY = new StylusPoint(pt.X + length * Math.Cos(theta) * Math.Cos(a), pt.Y + length * Math.Sin(theta) * Math.Sin(a));
SPC.Add(pt);
SPC.Add(spXY);
DrawBinaryTree(depth - 1, spXY, length * lengthScale, theta + deltaTheta);
DrawBinaryTree(depth - 1, spXY, length * lengthScale, theta - deltaTheta);
}
}
我尝试过使用 LinqPad 想出一个更简单的示例,但未能成功。