Iterating the Dictionary Class in VB.Net

Category : VB.Net

Made a dictionary to hold a date and an integer that

goes with that date but also needed to write a

function to average the total values – can not

call dictionary(i) like a normal array — have to

do it this way. (see italicized)


Public minutesDict As New Dictionary(Of Date, Integer)

 Public Function averageSteps() As Integer

        Dim totalSteps As Integer = 0
        Dim avgSteps As Integer = 0

        For Each kvp As KeyValuePair(Of Date, Integer) In minutesDict

            totalSteps += kvp.Value

        Next

        avgSteps = totalSteps / minutesDict.Count

    End Function