功能:在上传过程中拆分word文件
书签超过10个以上就不正常。
错误出现数组超出范围。 
for (int i = 0; i < doc.Books.Count; i++)
                    {
                       
                        if (i != doc.Books.Count)
                        {
                            oEnd = positions[i, 0];
                        }
                        else
                        {
                            oEnd = doc.Content.End;
                        }  //这行数组超出范围    Range tocopy = doc.Range(ref oStart, ref oEnd);
                        tocopy.Copy();                        Document docto = CreateDocument();
                        docto.Content.Paste();//贴出部分代码
private int[,] GetPosition(Document word) 
    { 
        int titleIndex = 0; 
         int bmcount = word.Books.Count;//书签个数为11 
        int[,] result = new int[bmcount, 2];       //result 结果最后两个没有赋值如:                                                                                                                      name     value                                                                                                                      [1,0]   333                                                                                                                     [1,1]   5567
                                                                                                                      ………… 
                                                                                                                     [9,0]   0 
                                                                                                                     [9,1]   0 
                                                                                                                     [10,0]   0 
                                                                                                                     [10,1]   0         for (int i = 1; i <= bmcount; i++) 
            { 
                index = i; 
                Book bm = word.Books.get_Item(ref index); 
               
                if (bm.Name == "book" + Convert.ToString(titleIndex)) 
                 {                   
                    result[titleIndex, 0] = bm.Start; 
                    result[titleIndex, 1] = bm.End; 
                    titleIndex++;               //  比如i循环到11后,titleIndex只是9,是否跟这个有关。 
                   
                } 
            } 
         
            return result;         
    } 帮忙解决下?

解决方案 »

  1.   

    for (int i = 0; i < doc.Books.Count; i++) 
                        { 
                          
                            if (i != doc.Books.Count) 
                            { 
                                oEnd = positions[i, 0]; 
                            } 
                            else 
                            { 
                                oEnd = doc.Content.End; 
                            }   //这行数组超出范围    Range tocopy = doc.Range(ref oStart, ref oEnd); 
                            tocopy.Copy(); 你的oStart没付值?
      

  2.   

    不是没有赋值问题吧
    为什么超过10以上就不正常了,提示数组超出范围.
    int [,]这个是有范围吗?
      

  3.   

    用 List<> 泛型
    怎么用也超不出范围啊
      

  4.   

    ref 关键字使参数按引用传递。其效果是,当控制权传递回调用方法时,在方法中对参数的任何更改都将反映在该变量中。若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字传递到 ref 参数的参数必须最先初始化。这与 out 不同,后者的参数在传递之前不需要显式初始化。http://msdn.microsoft.com/zh-cn/library/14akc2c7.aspx
      

  5.   

    positions {int[17, 2]} int[,]
    [0, 0] 4 int
    [0, 1] 18 int
    [1, 0] 2272 int
    [1, 1] 2291 int
    [2, 0] 2813 int
    [2, 1] 2835 int
    [3, 0] 3264 int
    [3, 1] 3288 int
    [4, 0] 3720 int
    [4, 1] 3748 int
    [5, 0] 4362 int
    [5, 1] 4389 int
    [6, 0] 4956 int
    [6, 1] 4983 int
    [7, 0] 5565 int
    [7, 1] 5591 int
    [8, 0] 5974 int
    [8, 1] 6000 int
    [9, 0] 6534 int
    [9, 1] 6557 int
    [10, 0] 0 int
    [10, 1] 0 int
    [11, 0] 0 int
    [11, 1] 0 int
    [12, 0] 0 int
    [12, 1] 0 int
    [13, 0] 0 int
    [13, 1] 0 int
    [14, 0] 0 int
    [14, 1] 0 int
    [15, 0] 0 int
    [15, 1] 0 int
    [16, 0] 0 int
    [16, 1] 0 int10以下全是0了.
    是不是不能用int [,]二维数组啊