我與VB.NET的工作,因爲一年前,現在我在用C#另一個項目的工作,我無法找到這個等價..Dictionary.Item在C#
在VB.NET
Dim dictionary As Dictionary(Of String, Decimal)
Dim oPerson As Person = Nothing
Dim key as string = "SomeValue"
If dictionary.ContainsKey(key) Then
oPerson = dictionary.Item(key)
End If
什麼是在C#中做到這一點的最佳方法?
我發現這樣的事情,但我不知道,如果是做的最好的方法..
Person oPerson = dictionary.Where(z => z.Key == key).FirstOrDefault().Val
您是否嘗試過使用在線代碼轉換器從VB到C# –
您只是試圖從字典中使用某個鍵來查找值是否正確? – adityaswami89
http://www.developerfusion.com/tools/convert/vb-to-csharp/試試這個鏈接 –