Assigning values to dictionary elements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • !NoItAll
    Contributor
    • May 2006
    • 297

    #1

    Assigning values to dictionary elements

    I've created a dictionary of a simple structure

    Code:
    Private Enum ClientStatus
        Alive = 0
        Zombie = 1
        Corpse = 2
    End Enum
    
    Private Structure ClientHeartbeat_type
       Dim Timestamp as DateTime
       Dim Status as ClientStatus
    End Structure
    
    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
    Code:
    Dim MyClient as new ClientHeartbeat_type with {.status = Clientstatus.Zombie, .Timestamp = Now}
    ClientList.add(ClientIP, MyClient)
    Later in my code I want to change values to the structure in the dictionary like this:

    Code:
    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:

    Code:
    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.
Working...