2014-01-08 54 views
0

如何在C#创建维数组三个组合?我收到错误消息C#维度数组的三个组合?

指数数组的边界之外。

foreach (XmlNode RegexExpression in XmlDataAccess.GetElementList(RefFile, "//regex")) 
{ 
    xRefList.Add(RegexExpression.InnerText); 
} 

foreach (XmlNode RegexExpression in XmlDataAccess.GetElementList(RefFile, "//word")) 
{ 
    WordList.Add(RegexExpression.InnerText); 
} 
foreach (XmlNode RegexExpression in XmlDataAccess.GetElementList(RefFile, "//title")) 
{ 
    TitleList.Add(RegexExpression.InnerText); 
} 

ArrayList xRefResult = MainDocumentPart_Framework.getReferenceContent(FileName, xRefList); 
ArrayList TitleResult = MainDocumentPart_Framework.getReferenceContent(FileName, TitleList); 
ArrayList WordResult = MainDocumentPart_Framework.getReferenceContent(FileName, WordList); 


var FinalResult = from first in TitleResult.ToArray() 
        from second in WordList.ToArray() 
        from third in xRefResult.ToArray() 
        select new[] { first, second, third }; 

foreach (var Item in FinalResult) 
{ 
    System.Windows.MessageBox.Show(Item.ToString()); 

    //I like to view show, all the combination of arrays 
    //first1, second1, third1 
    //first1, second1, third2 
    //first1, second1, third3 ........... 
} 
+0

代码的哪一部分是你得到的错误? – Obversity

+0

最后一个'foreach'块中的每个'item'实际上都是一个数组 - 所以你可能不想把它变成一个字符串。你需要一个嵌套循环。 '的foreach(在FinalResult变种的项目) { 的foreach(项VAR innerItem) { System.Windows.MessageBox.Show(innerItem.ToString()); } }' 也就是说,您可能不想使用消息框来显示它。不过,我相信你知道这一点。 – Obversity

+0

感谢您的快速回复,我想显示“System.Windows.MessageBox.Show(item); //我的意思是结合”第一[1]秒[1]第三[1] \ n第一[1]秒[ 1]第三[2]“就像这样 –

回答

0

我真的不知道你是什么样的输出后,我不认为你需要使用LINQ这一点。

string outputStr = ""; 

for(int x = 0;x<xRefList.Count;x++) 
{ 
    for(int y = 0;y<WordList.Count;y++) 
    { 
    for(int z = 0;z<TitleList.Count;z++) 
    { 
     outputStr += xRefList[x] + " " + WordList[y] + " " + TitleList[z] + "\n"; 
    } 

    } 
} 

MessageBox.Show(outputStr); 

会是这样的工作?