Question : .NET Generic collection

When I try to run this query I get the error
Unable to cast object of type 'WhereEnumerableIterator`1[System.Collections.Generic.KeyValuePair`2[System.Int32,SoftwareHobbitData.clsMacroVariable]]' to type 'System.Collections.Generic.Dictionary`2[System.Int32,SoftwareHobbitData.clsMacroVariable][]'.

All I am trying to do is passed a filtered collection back.  What am I doing wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
ReadOnly Property ApplicationMacroVariables(ByVal iMacroID As Integer) As Dictionary(Of Integer, clsMacroVariable)
        Get
            Dim query As Dictionary(Of Integer, clsMacroVariable)()
 
            query = _ApplicationMacroVariable.Values.Where(Function(Variables) Variables.Value.iMacroID = iMacroID)
            Return query.Equals
        End Get
    End Property

Answer : .NET Generic collection

The Where extension method returns IEnumerable but you're trying to assign it to a variable of type Dictionary. Add a ToDictionary call to your statement:

query = _ApplicationMacroVariable.Values.Where(Function(Variables) Variables.Value.iMacroID = iMacroID).ToDictionary(Function(Variables) Variables.Value.iMacroID)
Random Solutions  
 
programming4us programming4us