2013-04-11 48 views
0

鑑於以下兩個未知長度的IEnumerable(Of String),我如何產生非明顯的聯合?如何使用LINQ生成字符串的非獨特聯合?

Dim theseStrings As IEnumerable(Of String) = 
    {"true", "true", "true", "true", "true"} 
Dim thoseStrings As Ienumerable(Of String) = 
    {"false", "true", "false", "false"} 

結果應該是這樣的:

{"false", "true", "false", "false", "true"} 

這意味着

  • 當兩個不同意,的resultCount必須等於theseStrings
  • 的優先

規則

  • 沒有清單或任何具體
  • 沒有循環

我已經試過

Dim result = theseStrings.Union(thoseStrings) 
' result = {"true"} 

Dim result = theseString.Concat(thoseStrings) 
' result = {"true", "true", "true", "true", "true", "false", "true", "false", "false"} 

回答

0

解決方案:

Dim result As IEnumerable(Of String) = 
    theseStrings.Select(
     Function(value, index) _ 
      If(thoseStrings(index) IsNot Nothing, thoseString(index), value)) 

請留言,如果這可以清理。

相關問題