日期:2014-05-18  浏览次数:21116 次

什么是unsafe编译选项,如何设置unsafe选项
我最近用C#做一个动态链表,来实现我自定义的一个类myLine
还有一个结构lineNode
unsafe   struct   lineNode
{
double   x;
double   y;
//两个存放指针的指针变量,用于存放上一个节点和下一个节点的地址
lineNode*   UpNode;
lineNode*   NextNode;
}

///////////////////////////////////
public   class   myLine
{
public   lineNode*   startNode=null;
public   lineNode*   EndNode=null;

public   int   nodesCount//属性返回myLine类中lineNode节点的个数
    {
        if   (lineNode==null)  
        {
        return   0;
        }
        lineNode*   tempNode=this.startNode;
        int   tempCount=1;
        while(temp-> nextNode!=null)
        {
          tempNode=tempNode.nextNode;
          tempCount++;
        }
        return   tempCount;
    }
    private   myLine()
        {//将访问关键字设为private   可以防止实例化没有节点的Line
        }
    public   myLine(linenode*   start,lineNode*   end)
    {
        this.startNode=start;
        this.endNode=end;
        this.startNode-> upNode=null;
        this.startNode-> nextNode=end;
        this.endNode-> upNode=startNode;
        this.endNode-> nextNode=null;
    }
    public   void   Append(lineNode*   aNewNode)
      {
          aNewNode-> upNode=this.endNode;
          aNewNode-> nextNode=null;
          this.endNode-> nextNode=aNewNode;
          this.endNode=aNewNode;

        }
        public   void   InsertAt(lineNode*   aNewNode,int   index)
        {
            if   (index==0||index> =this.nodesCount+2)索引值是从1to     this.nodesCount
                      {
                            //抛出一个异常“索引超出上限”;
                            return   ;
                        }
            else
                  {
                        请大家帮我完成这一部份,实现把新节点插入到myLine中,
                    }  
          }
}

------解决方案--------------------
unsafe:
解决方案管理器--Properties--生成选项卡--允许不安全代码 打勾。