OneToManyDictionary<TKey, TValueKey, TValue> 类
一对多映射关系的字典。每个键都对应一个内部字典,该内部字典将键值映射到相应的值。
实现
IDictionary<TKey, Dictionary<TValueKey, TValue>>
IReadOnlyDictionary<TKey, Dictionary<TValueKey, TValue>>
继承成员
命名空间: Fantasy.DataStructure.Dictionary
程序集: Fantasy.Net.dll
语法
public class OneToManyDictionary<TKey, TValueKey, TValue> : Dictionary<TKey, Dictionary<TValueKey, TValue>>, IDictionary<TKey, Dictionary<TValueKey, TValue>>, ICollection<KeyValuePair<TKey, Dictionary<TValueKey, TValue>>>, IReadOnlyDictionary<TKey, Dictionary<TValueKey, TValue>>, IReadOnlyCollection<KeyValuePair<TKey, Dictionary<TValueKey, TValue>>>, IEnumerable<KeyValuePair<TKey, Dictionary<TValueKey, TValue>>>, IDictionary, ICollection, IEnumerable, IDeserializationCallback, ISerializable where TKey : notnull where TValueKey : notnull
类型参数
名称 | 描述 |
---|---|
TKey | 外部字典中的键类型。 |
TValueKey | 内部字典中的键类型。 |
TValue | 内部字典中的值类型。 |
构造函数
| 编辑本文 查看源代码OneToManyDictionary()
创建一个新的 OneToManyDictionary<TKey, TValueKey, TValue> 实例。
声明
public OneToManyDictionary()
OneToManyDictionary(int)
创建一个新的 OneToManyDictionary<TKey, TValueKey, TValue> 实例,并指定最大缓存数量。
声明
public OneToManyDictionary(int recyclingLimit = 0)
参数
类型 | 名称 | 描述 |
---|---|---|
int | recyclingLimit | 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC. 2:设置成0不控制数量,全部缓存 |
方法
| 编辑本文 查看源代码Add(TKey, TValueKey, TValue)
向字典中添加指定的键值对。
声明
public void Add(TKey key, TValueKey valueKey, TValue value)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要添加键值对的键。 |
TValueKey | valueKey | 要添加键值对的内部字典键。 |
TValue | value | 要添加的值。 |
Clear()
清空字典中的所有键值对,并将不再使用的内部字典实例放回对象池中。
声明
public void Clear()
Contains(TKey, TValueKey)
检查是否包含指定的键值对。
声明
public bool Contains(TKey key, TValueKey valueKey)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 外部字典中的键。 |
TValueKey | valueKey | 内部字典中的键。 |
返回
类型 | 描述 |
---|---|
bool | 如果包含指定的键值对,则为 true;否则为 false。 |
First(TKey)
获取指定键的第一个值。
声明
public TValue First(TKey key)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要获取第一个值的键。 |
返回
类型 | 描述 |
---|---|
TValue |
Remove(TKey, TValueKey)
从字典中移除指定的键值对。
声明
public bool Remove(TKey key, TValueKey valueKey)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要移除键值对的键。 |
TValueKey | valueKey | 要移除键值对的内部字典键。 |
返回
类型 | 描述 |
---|---|
bool | 如果成功移除键值对,则为 true;否则为 false。 |
Remove(TKey, TValueKey, out TValue)
从字典中移除指定的键值对。
声明
public bool Remove(TKey key, TValueKey valueKey, out TValue value)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要移除键值对的键。 |
TValueKey | valueKey | 要移除键值对的内部字典键。 |
TValue | value | 如果成功移除键值对,则为移除的值;否则为默认值。 |
返回
类型 | 描述 |
---|---|
bool | 如果成功移除键值对,则为 true;否则为 false。 |
RemoveKey(TKey)
移除字典中的指定键及其相关的所有键值对。
声明
public void RemoveKey(TKey key)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 要移除的键。 |
TryGetValue(TKey, TValueKey, out TValue)
尝试获取指定键值对的值。
声明
public bool TryGetValue(TKey key, TValueKey valueKey, out TValue value)
参数
类型 | 名称 | 描述 |
---|---|---|
TKey | key | 外部字典中的键。 |
TValueKey | valueKey | 内部字典中的键。 |
TValue | value | 获取的值,如果操作成功,则为值;否则为默认值。 |
返回
类型 | 描述 |
---|---|
bool | 如果操作成功,则为 true;否则为 false。 |