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 2 1661
With generic Dictionary, the type of iterated item is
"KeyValuePair<(Of <(TKey, TValue>)>) Generic Structure" http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx
--
Teemu Keiski
AspInsider, ASP.NET MVP http://blogs.aspadvice.com/joteke http://teemukeiski.net
"D Browne" <go******@community.nospamwrote in message
news:76**********************************@microsof t.com...
>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
Yes that was the issue. I don't know how I missed that! Thanks.
"Teemu Keiski" <jo****@aspalliance.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
With generic Dictionary, the type of iterated item is
"KeyValuePair<(Of <(TKey, TValue>)>) Generic Structure" http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx
--
Teemu Keiski
AspInsider, ASP.NET MVP http://blogs.aspadvice.com/joteke http://teemukeiski.net
"D Browne" <go******@community.nospamwrote in message
news:76**********************************@microsof t.com...
>>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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sanjay Vyas |
last post by:
Sorry, forgot to cross post this one..
This is rather unusual as we would expect any Collection class to implement
ICollection interface and furthermore a Dictionary class should implement...
|
by: John C |
last post by:
I'm new to C#, so just point me at the correct reference material if this
question has been answered before.
When creating a new class which implements the IDictionary interface, two
versions of...
|
by: Nick Flandry |
last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my
development environment (Win2K server running IIS 5) and a test environment (also Win2K server
running IIS...
|
by: John Howard |
last post by:
Making the following call to a local MSAccess database works fine:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim intRows As Integer
Dim strSQL As String
Dim ds As New...
|
by: Hifni Shahzard |
last post by:
Hi,
I got a stored procedure, where it returns a value. But if I execute it. It
gives an error as "Invalid cast from System.Int32 to System.Byte.". To make
clear how do I execute this, below I'm...
|
by: John |
last post by:
I have a collection of properties from a WMI query and I
want to recreate the collection and exclude duplicates and
then enumerate.
In VBScript I used the "Scripting.Dictionary" object and
the...
|
by: Zark3 |
last post by:
Hi all,
I was wondering if anybody could enlighten me on the possibility of
dynamic casting. Or, well, whether or not I'm actually trying to do
this the right way.
What I have is a base class...
|
by: J055 |
last post by:
Hi
I have an OrderedDictionary object where the key is an enum. Is there an
easy way to cast it to an integer? Examples/document appreciated.
Thanks
Andrew
|
by: pierre.k |
last post by:
Hello,
how can I do a cast like
IDictionary<int, stringas IDictionary<object, string ?
Thanks in advance for your help,
pierre.k
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |