- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用字典来查找我正在处理的程序。我在字典中运行了一堆键,我希望有些键没有值。我 catch 了 KeyNotFoundException
就在它发生的地方,吸收它。所有其他异常将传播到顶部。这是处理这个问题的最佳方法吗?或者我应该使用不同的查找?该字典使用 int 作为键,使用自定义类作为值。
最佳答案
Dictionary<int,string> dictionary = new Dictionary<int,string>();
int key = 0;
dictionary[key] = "Yes";
string value;
if (dictionary.TryGetValue(key, out value))
{
Console.WriteLine("Fetched value: {0}", value);
}
else
{
Console.WriteLine("No such key: {0}", key);
}
关于c# - 处理 KeyNotFoundException 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/606636/
当我尝试删除具有多对一复合键的对象时,NHibernate 抛出异常。保存对象工作正常。这是异常(exception): [KeyNotFoundException: The given key wa
我正在存储一个二维数组,它表示向量之间的距离矩阵作为 Dictionary .我的实现 DistanceCell有两个字符串字段代表被比较的向量。 class DistanceCell { p
我正在尝试修改字典中的值,但编译器抛出 KeyNotFoundException。我敢肯定,我在字典中声明了该键,因为我正在调用 GenerateEmptyChunks() 方法,该方法用具有其位置键
我有一段看似简单的代码,它一直在抛出我不希望发生的错误: // Private member private Dictionary m_Completed; // Later on, during s
我正在尝试连接到一个免费的在线数据库 (db4free.net),但我无法连接,因为当程序尝试打开连接时会抛出 KeyNotFoundException。 这是我的代码: public static
我正在使用以下方法将 JSON 字符串反序列化到我自己的类中: JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictio
我有一个随机抛出“KeyNotFoundException”的 C# Silverlight 应用程序。我不知道找不到什么 key 。这让我想到了两个问题: KeyNotFoundException
我有一些处理大量 response 的代码并行地从我的数据库中获取对象(使用 AsParallel() )。每个response有很多components . responses可能共享相同的组件。我
type bytesLookup = Map type lookupList = bytesLookup list let maps:bytesLookup = Map.empty let print
好吧,我正在尝试从表单更新数据库中的信息。但是当我调用 db.SaveShanges() 时,我得到 KeyNotFoundException。我正在使用 MVC3 和 EF 4.1。我使用 Cont
我猜测除了异常之外的所有信息都是额外的并且几乎不相关(并且在这里是为了完整性)。问题是:根据下面的异常,到底遇到了什么问题? 我无法理解异常消息。据我所知,将 BsonDocument 映射到 Chi
我正在使用字典来查找我正在处理的程序。我在字典中运行了一堆键,我希望有些键没有值。我 catch 了 KeyNotFoundException就在它发生的地方,吸收它。所有其他异常将传播到顶部。这是处
我正在尝试测试从我的 Nancy 应用程序返回的模型是否符合预期。我已关注文档 here但每当我调用 GetModel扩展方法它抛出 KeyNotFoundException . System.Col
当我尝试在 visual studio 2012 下的 asp.net web api 项目中使用 C# 中的嵌套字典时出现错误代码。此代码示例实际上是从其他支持者在 stack-overflow 上
我正在使用 unity 尝试连接到 MySQL 数据库。数据库运行良好,代码运行良好(在 Visual Studio 2010 中)。但是,当在 Unity 中运行以下命令时: // Connect
下面的代码 new Dictionary> { ["a"] = {1}, }; 抛出运行时 KeyNotFoundException ,尽管 {1} 是一个格式正确的数组(即 int[] a
如果有人问这个问题,我很抱歉,因为我错过了一些非常基本的东西。 我在 Unity 中搜索字典键时收到KeyNotFoundException:字典中不存在给定的键。然而,在我的(仍然很小)的项目中,我
我有一个 RegistryKey 作为我字典的键。 我似乎无法为该特定键设置值。无论我做什么,我都会收到 KeyNotFoundException。 key 确实存在,我在前一行创建了它 例如: pu
不确定为什么我每次尝试连接时都会收到错误消息。我尝试了很多东西。当我在手动连接时输入错误的密码时,它会显示未授予访问权限或其他任何内容,所以我知道它已连接但是当它连接时我收到这个奇怪的错误。 An u
我正在处理遗留的 ASP.NET 代码库,该代码库有 一些 信息存储在 DataTable 对象的缓存中(通过企业库)。它是一个多用户、Intranet 环境,在 .NET 4.0 中运行。生产中存在
我是一名优秀的程序员,十分优秀!