c# - 如何在c#中以两种方式使用字典

标签 c#

public static Dictionary<int, string> dic = new Dictionary<int, string>() { 
            {1,"anystring1"},
            {2,"anystring2"}};

我需要用这个

string str= dic[1]; // it is possible

int a=dic["anystring1"]; // My dream is it

最佳答案

使用另一个 Dictionary<>并以键/值的相反顺序使用它。

关于c# - 如何在c#中以两种方式使用字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4191462/

相关文章:

c# - 为什么 C# Powershell 方法在 Windows 应用程序中有效,但在 Web 应用程序中无效

c# - 流利的 Nhibernate : could not resolve property

c# - 从另一个项目运行 .net 核心项目

c# - 如何根据页面名称而不是asp.net中的查询字符串更改内容

c# - Telegram bot - 向/启动命令添加唯一键

c# - skynet 基准测试中的 TPL 样本并非真正并行?

c# - 如何测试C#传真程序?

C# 获取大目录的文件名和上次写入时间

c# - VB 与 C# : Why is this possible?

c# - 在c#中自定义ToolStripMenuItems