C# KEY VALUE 字典 分别生成Key List 和Value List
在C#中,可以通过以下方法分别生成key和value的列表:
- 使用
Keys属性获取所有的key,并将其转换为列表:
Dictionary<string, int> dict = new Dictionary<string, int>();
List<string> keyList = dict.Keys.ToList();
- 使用
Values属性获取所有的value,并将其转换为列表:
Dictionary<string, int> dict = new Dictionary<string, int>();
List<int> valueList = dict.Values.ToList();
注意,上述示例中的Dictionary<string, int>是一个键为string类型、值为int类型的字典。你可以根据具体的字典类型进行相应的调整。
原文地址: https://www.cveoy.top/t/topic/ihbi 著作权归作者所有。请勿转载和采集!