gpt4 book ai didi

c# - Java 的 AbstractMap 在 C# 中的等价物是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:36:58 24 4
gpt4 key购买 nike

我需要创建一个公开 IDictionary<K,V> 的对象界面,但我不想填写整个界面实现。

拥有与 Java 的 AbstractDictionary 等效的东西会很好,它让您几乎没有什么可以插入完整的字典(Java 中的 HashMap):

  • 如果你不需要迭代集合,你有一个单一的方法来实现(TryGetValue)
  • 如果您希望它是可写的,您可以实现另一个条目(添加)。

最佳答案

赢智的PowerCollections library包括一个 DictionaryBase 类 ( source code ),它实现了大部分标准 IDictionary 接口(interface)。来自类(class)的文档评论:

DictionaryBase is a base class that can be used to more easily implement the generic IDictionary<T> and non-generic IDictionary interfaces.

To use DictionaryBase as a base class, the derived class must override Count, GetEnumerator, TryGetValue, Clear, Remove, and the indexer set accessor.

关于c# - Java 的 AbstractMap 在 C# 中的等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/339709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com