是列表<;图形SPATH>;可能在C#中?

是列表<;图形SPATH>;可能在C#中?,c#,list,generics,drawing2d,graphicspath,C#,List,Generics,Drawing2d,Graphicspath,我尝试使用GraphicsPath列表而不是数组,因为我不知道用户将创建的路径数 List<GraphicsPath> PathDB = new List<GraphicsPath>(); 但是当我尝试使用列表中的GraphicsPath时,尽管Count属性是正确的,但由于参数异常,我无法使用下面这样的对象 num = PathDB.Count; for(int k=0; k < num; k++) { using(GraphicsPath m

我尝试使用GraphicsPath列表而不是数组,因为我不知道用户将创建的路径数

List<GraphicsPath> PathDB = new List<GraphicsPath>();
但是当我尝试使用列表中的GraphicsPath时,尽管Count属性是正确的,但由于参数异常,我无法使用下面这样的对象

num = PathDB.Count;
for(int k=0; k < num; k++)
   {
      using(GraphicsPath myCurrentPath = new GraphicsPath())
      {
         myCurrentPath = PathDB[k];
         myCurrentPath.AddLine(0,0,400,400); //at this stage exception is thrown 
         myGraphics.DrawPath(myPen, myCurrentPath)
      }
   }
num=PathDB.Count;
for(int k=0;k
这与被处置有关吗??还是smt做错了

using(GraphicsPath myPath = new GraphicsPath())
{
   myPath.AddPolygon(myPoints);
   PathDB.Add(myPath);
} // this disposes myPath

这是一个本地图形路径。您的
使用
block
Dispose
s将其置于作用域之后(如果完成)。因此,您需要使用
块删除该
,并在不再需要路径时处理它们。

异常说明了什么?是的,该对象已被处置,因此您不应再使用它。你想用它达到什么目的?使用这个语句毫无意义。当然,您不能销毁该列表中存储的任何内容,从列表中删除该内容时必须进行销毁。C#足够聪明,不会造成破坏,但你可能在其他地方也这样做。我不明白。为什么要在循环中创建一个新的
GraphicsPath
实例,用一个现有的值(您以前已经处理过)覆盖变量,然后不使用它就丢弃新创建的值?您似乎不清楚使用
时实际做了什么(或者您的代码在这方面做了什么)。
using(GraphicsPath myPath = new GraphicsPath())
{
   myPath.AddPolygon(myPoints);
   PathDB.Add(myPath);
} // this disposes myPath