Invalid cast with IDictionary

D

D Browne

I think this should be a very simple test but I can't figure out what the
problem is:

Imports ConsoleApplication1.FruitDetails

Public Class FruitDetails
Private m_fruitInfo As IDictionary(Of String, FruitColor)
Public Property FruitInfo()
Get
Return m_fruitInfo
End Get
Set(ByVal value)
m_fruitInfo = value
End Set
End Property

Public Enum FruitColor
orange
yellow
green
End Enum
End Class

Module Module1

Sub Main()
Dim Detail As New FruitDetails

Dim Fruit As New Dictionary(Of String, FruitColor)
Fruit.Add("Banana", FruitColor.yellow)

Detail.FruitInfo = Fruit

Console.Write(GetFruit(Detail))

End Sub

Public Function GetFruit(ByVal FruitInformation As FruitDetails) As
String

Try
For Each Fruit As DictionaryEntry In FruitInformation.FruitInfo
'specific cast is not valid
Return String.Concat("This ", Fruit.Key, "Is ", Fruit.Value)
Next
Catch ex As Exception
Console.Write(ex.ToString)
End Try

End Function

End Module


The information I'm really looking for is the first DictionaryEntry in
DetailLevel without having to do a For Each loop ... maybe
IEnumerator.Entry?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top