Working with Dictionaries - Practice3 Dictionaries Workflow Question

I have a question on what the following statement is actually doing on the right side:
WinnerCounts(WinnerName) = WinnerCounts(WinnerName) + 1

  • WinnerCounts is user created Dictionary(Sting, Int32)
  • WinnerName is the first input form in the For Each Activity which will hold the value of TourDeFranceWinners.Values
  • TourDeFranceWinners is a dictiontionary(Int32, String) filled with{{2006,“Oscar Pereiro”},{2007,“Alberto Contador”}} type of info

So in the first iteration this staement would essentially be:
WinnerCounts(“Oscar Pereiro”) = WinnerCounts(“Oscar Pereiro”) + 1

What I want to know is what is the right side of this doing? Because it is a dictionary where the Key is stated, do dictionaries in VB.net automatically correspond to something like a ‘+ 1’ as going to the Value of the dictionary?

For example if ‘WinnerCounts’ was a Dictonary(String, String), and the statement was:
WinnerCounts(“Oscar Pereiro”) = WinnerCounts(“Oscar Pereiro”) + “Good”

Would ‘Good’ automatically be set as the Value side of this dictionary? Thanks.

Hi
Usually a dictionary variable will be having a collection of key-value pairs in it
Where the left side is key and right side is value here

Key - 2006, 2007
It’s corresponding value is
Value - Oscar Pereiro, Alberto Contador

So if I call the dictionary variable like this
WinnerCounts(“Oscar Pereiro”) = WinnerCounts(“Oscar Pereiro”) + 1

Here WinnerCounts is a variable with (string, int) as (key,value)

So if I call with key of string WinnerCounts(“Oscar Pereiro”) then it will give us a int value as a output
Say for example it has 100 as value for the key Oscar Pereiro in it then

WinnerCounts(“Oscar Pereiro”) = WinnerCounts(“Oscar Pereiro”) + 1

WinnerCounts(“Oscar Pereiro”) = 100 + 1

WinnerCounts(“Oscar Pereiro”) = 101

As key is of type string and value is of type int32

Now this 101 will be assigned to that key Oscar Pereiro as a value along the dictionary which has several such key and value pair in it

So it means we are adding 1 to each value for its key

And here

It will concatenate the value of that key with Good suppose the value for the key Oscar Pereiro was early like “He is “

Then on doing this assign it will put like this
WinnerCounts(“Oscar Pereiro”) = ”He is “+”Good”
WinnerCounts(“Oscar Pereiro”) = ”He is Good”

As here both key and value is of type string

Cheers @css

Thank you Palaniyappan, crystal clear now, thanks.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.