I have some legacy code which consists of:
A Dictionary
(dictParts
) populated during startup with approx. 350,000 items (does not change during runtime).
dictParts
is a System.Collections.Generic.Dictionary(Of String, System.Data.DataRow)
.
Each item in dictParts
is a System.Collections.Generic.KeyValuePair(Of String, System.Data.DataRow)
.
An Array
(arrOut
) which frequently has items added and removed (typically between 2-6 items in the array).
arrOut
is a System.Array
containing only string
s.
Each time the array changes I need to see if:
- All the items in the array exist in the index
- Some of the items in the array exist in the index
I imagine that looping through the index 350,000 every time the array changes is going to have massive performance hit and looked to LINQ to help.
I have tried the following:
Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
Dim dictParts = New Dictionary(Of Integer, String) _
From {{1, "AA-10-100"}, _
{2, "BB-20-100"}, _
{3, "CC-30-100"}, _
{4, "DD-40-100"}, _
{5, "EE-50-100"}}
Dim arrOut() As String = {"AA-10-100", "BB-20-100", "CC-30-100"}
'Tried
Dim allPartsExist As IEnumerable(Of String) = arrOut.ToString.All(dictParts)
'And this
Dim allOfArrayInIndex As Object = arrOut.ToString.Intersect(dictParts).Count() = arrOut.ToString.Count
End Sub
I keep getting errors: Unable to cast object of type 'System.Collections.Generic.Dictionary2[System.Int32,System.String]' to type 'System.Collections.Generic.IEnumerable
1[System.Char]'.
Please could someone advise where I am going wrong.