循环导致cad崩溃,敬请高手指点。
<p>刚开始用C#开发AutoCAD,向绘制几条Pline,但在使用while、for等循环的过程中,总是导致cad崩溃。</p><p>发生问题的代码如下:</p><p> Polyline[] MidBox = new Polyline;<br/> for (int ILoop = 0; ILoop < 5; ILoop++)<br/> {<br/> MidBox.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);<br/> MidBox.AddVertexAt(1, new Point2d(1, 1), 0, 0, 0);<br/> MidBox.AddVertexAt(2, new Point2d(2, 2), 0, 0, 0);<br/> MidBox.AddVertexAt(3, new Point2d(3, 3), 0, 0, 0);<br/> MidBox.AddVertexAt(4, new Point2d(4, 4), 0, 0, 0);<br/> MidBox.AddVertexAt(5, new Point2d(5, 5), 0, 0, 0);<br/> ////向块表记录中添加边箱线<br/> //btr.AppendEntity(MidBox);<br/> //trans.AddNewlyCreatedDBObject(MidBox, true);<br/> }</p><p></p><p>请问是怎么回事?</p> <p>这是基本语法问题</p><p>Polyline[] MidBox = new Polyline;</p><p>这里创建了5个元素的Polyline的数组,但每个元素都是空值</p><p>for循环开始直接调用空值MidBox,自然崩溃</p><p>解决:在循环开始加</p><p>MidBox = new Polyline();</p>
页:
[1]