Why can I not Remove a key from a ConcurrentDictionary without providing an out parameter for the value?
本问题已经有最佳答案,请猛点这里访问。
请考虑以下简单的代码段:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using System.Collections.Concurrent; using System.Collections.Generic; namespace WTF { class Program { static void Main(string[] args) { ConcurrentDictionary<int ,int> dict = new ConcurrentDictionary<int, int>(); dict.Remove(5); } } } |
我检查了两次和三次文档:
但是,显然,编译器不同意:
1 2 3 4 | 1>------ Build started: Project: WTF, Configuration: Debug Any CPU ------ 1>Program.cs(12,18,12,24): error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'CollectionExtensions.Remove<TKey, TValue>(IDictionary<TKey, TValue>, TKey, out TValue)' 1>Done building project"WTF.csproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== |
我错过了什么?我做错了什么?还是我看错了医生?
如果这很重要,据我所知,我在.NET核心2.1上。