You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
835 B
C#
29 lines
835 B
C#
using System.Collections.Generic;
|
|
|
|
namespace SigmaDrawerElement
|
|
{
|
|
/// <summary>
|
|
/// 字典辅助类
|
|
/// </summary>
|
|
public class DictionaryHelper
|
|
{
|
|
/// <summary>
|
|
/// 反转字典的 Key Value 组成一个新的字典
|
|
/// </summary>
|
|
/// <typeparam name="TKey">字典 Key 类型</typeparam>
|
|
/// <typeparam name="TValue">字典 Value 类型</typeparam>
|
|
/// <param name="dict">字典</param>
|
|
/// <returns>反转后的新字典</returns>
|
|
public static Dictionary<TValue, TKey> Reverse<TKey, TValue>(Dictionary<TKey, TValue> dict)
|
|
{
|
|
var newDict = new Dictionary<TValue, TKey>();
|
|
foreach (var kv in dict)
|
|
{
|
|
newDict[kv.Value] = kv.Key;
|
|
}
|
|
|
|
return newDict;
|
|
}
|
|
}
|
|
}
|