在 Silverlight 应用程序中从字典中获取键和值
Get the Key and Value from Dictionary in Silverlight Application
我需要在 silverlight 应用程序中从字典(从 Web 服务返回)中获取值。
我在变量 val 中得到字典值。
serviceclient.GetMappingCompleted += (obj, val) =>
{
//here I need the Key and Value result
int key = ?
string value = ?
}
您可以使用 val.Result
访问字典。这是代码:
foreach (KeyValuePair<int, string> item in val.Result)
{
int key = item.Key;
string value = item.Value;
}
如果您正在查找字典中的第一个 KeyValuePair
,您可以试试这个(不要忘记添加 using System.Linq;
,以便 First
方法可用):
var key = val.Result.First().Key;
var value = val.Result.First().Value;
我需要在 silverlight 应用程序中从字典(从 Web 服务返回)中获取值。
我在变量 val 中得到字典值。
serviceclient.GetMappingCompleted += (obj, val) =>
{
//here I need the Key and Value result
int key = ?
string value = ?
}
您可以使用 val.Result
访问字典。这是代码:
foreach (KeyValuePair<int, string> item in val.Result)
{
int key = item.Key;
string value = item.Value;
}
如果您正在查找字典中的第一个 KeyValuePair
,您可以试试这个(不要忘记添加 using System.Linq;
,以便 First
方法可用):
var key = val.Result.First().Key;
var value = val.Result.First().Value;