您的位置:首页 > 产品设计 > UI/UE

Dictionary.TryGetValue 方法

2010-12-17 14:26 337 查看
public bool TryGetValue (
TKey key,
out TValue value
)

参数

key 要获取的值的键。 value 当此方法返回值时,如果找到该键,便会返回与指定的键相关联的值;否则,则会返回 value 参数的类型默认值。该参数未经初始化即被传递。

返回值

如果 Dictionary 包含具有指定键的元素,则为 true;否则为 false

string value = "";
if (openWith.TryGetValue("tif", out value))
{
Console.WriteLine("For key = /"tif/", value = {0}.", value);
}
else
{
Console.WriteLine("Key = /"tif/" is not found.");
}
...        // The indexer throws an exception if the requested key is
// not in the dictionary.
try
{
Console.WriteLine("For key = /"tif/", value = {0}.",
openWith["tif"]);
}
catch (KeyNotFoundException)
{
Console.WriteLine("Key = /"tif/" is not found.");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐