By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Assigning values to dictionary elements

P: 296
I've created a dictionary of a simple structure

Expand|Select|Wrap|Line Numbers
  1. Private Enum ClientStatus
  2.     Alive = 0
  3.     Zombie = 1
  4.     Corpse = 2
  5. End Enum
  7. Private Structure ClientHeartbeat_type
  8.    Dim Timestamp as DateTime
  9.    Dim Status as ClientStatus
  10. End Structure
  12. Private ClientList as Dictionary(of String, ClientHeartbeat_type)
The intent is that the KEY for the dictionary when I create an element will be the IPV4 IP Address of the client.
So I add an element to the dictionary as follows
Expand|Select|Wrap|Line Numbers
  1. Dim MyClient as new ClientHeartbeat_type with {.status = Clientstatus.Zombie, .Timestamp = Now}
  2. ClientList.add(ClientIP, MyClient)
Later in my code I want to change values to the structure in the dictionary like this:

Expand|Select|Wrap|Line Numbers
  1. ClientList(ClientIPAddress).Status = ClientStatus.Alive
The problem is that it complains: "The expression is a value and therefore cannot be the target of an assignment"

But this works:

Expand|Select|Wrap|Line Numbers
  1. ClientList(ClientIP) = New ClientHeartbeat_type with {.status = Clientstatus.Alive, .Timestamp = Now}
So I am updating the entire structure. Why won't it let me update just one element of the structure.
Sep 19 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.