Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 我怎样才能反复阅读字典_Vb.net_Dictionary_Foreach_Iteration - Fatal编程技术网

Vb.net 我怎样才能反复阅读字典

Vb.net 我怎样才能反复阅读字典,vb.net,dictionary,foreach,iteration,Vb.net,Dictionary,Foreach,Iteration,我试图使用for-each语句遍历我创建的字典列表中的所有值。我希望能够打印出所有的值。以及调用个人值 Dim dblExpenses = New Dictionary(Of String, Double) dblExpenses.Add("Travel_Days", CDbl(txtTravelDays.Text)) dblExpenses.Add("Private_Vehicle_Miles", CDbl(txtPrivateVehicleMiles.Text))

我试图使用for-each语句遍历我创建的字典列表中的所有值。我希望能够打印出所有的值。以及调用个人值

 Dim dblExpenses = New Dictionary(Of String, Double)
    dblExpenses.Add("Travel_Days", CDbl(txtTravelDays.Text))
    dblExpenses.Add("Private_Vehicle_Miles", CDbl(txtPrivateVehicleMiles.Text))
    dblExpenses.Add("Airfare", CDbl(txtAirfare.Text))
    dblExpenses.Add("Car_Rental_Fees", CDbl(txtCarRentalFees.Text))
    dblExpenses.Add("Parking_Fees", CDbl(txtParkingFees.Text))
    dblExpenses.Add("Taxi_Charges", CDbl(txtTaxiCharges.Text))
    dblExpenses.Add("Registration_Fees", CDbl(txtRegistationFees.Text))
    dblExpenses.Add("Lodging_Per_Night", CDbl(txtLodgingPerNight.Text))
    dblExpenses.Add("Meals", CDbl(txtMeals.Text))

    For Each item As Double In dblExpenses

    Next
提前谢谢你的帮助。我做了一些搜索,但是我找不到任何使用for each来迭代字典的方法。

您应该使用

For Each item As KeyValuePair(Of String, Double) In dblExpenses
    'item.Key for key
    'item.Value for value
Next
或者,您可以尝试只获取值

For Each item As Double In dblExpenses.Values
    'item
Next

您需要遍历密钥集合。谢谢您,这非常有效。使用KeyValuePair绝对是我应该多读的东西。给他们一个向上箭头的投票!没有足够的声誉去做这件事。