突然想到之前碰到的一个优化的面试题,现在想想switch用的太傻

 public enum FormatType
{
GetKey,
GetValue
}
public class Format
{
private static string Get(Dictionary<string, string> dict, FormatType formatType, string code)
{
if (formatType == FormatType.GetKey)
return dict.FirstOrDefault(d => d.Value == code).Key;
else
return dict.FirstOrDefault(d => d.Key == code).Value;
}
public static string GetNation(FormatType formatType, string code)
{
Dictionary<string, string> dict = new Dictionary<string, string>{
{"","汉族"},
{"","藏族"},
{"","壮族"},
{"","朝鲜族"}
//这里省略其它......
};
return Get(dict, formatType, code);
}
}

使用:
获取"汉族"的编码
string key = Format.GetNation(FormatType.GetKey, "汉族");
获取"01"代表的民族
string value = Format.GetNation(FormatType.GetValue, "01");

--------------------------------------------------------------------------------------------

有的用委托有的用反射,这个讲的挺详细

最新文章

  1. go并发
  2. protoc 和 protoc-gen-go 产生的 proto 文件代码对比
  3. JavaScript 为什么要通过原型 prototype 调用函数, 而不是直接调用?
  4. noip2006T1 能量项链
  5. 多线程程序设计学习(4)guarded suspension模式
  6. Unity 5.4大赞:HTC Vive经典The lab渲染器开源
  7. C 中随机数
  8. [iOS] Create TableView &amp; customize UITableViewCell
  9. C++程序设计实践指导1.10二维数组元素换位改写要求实现
  10. Can&#39;t load IA 32-bit .dll on a AMD 64-bit platform
  11. java/php/c#版rsa签名以及验签实现
  12. 2014在百度之星资格赛的第二个问题Disk Schedule
  13. swift 之函数式编程(一)
  14. 给COCO数据集的json标签换行
  15. springboot性能优化
  16. LAB8 android
  17. Mysql Group by 使用解析
  18. mysql 安装部署
  19. MySQL数据查询之多表查询
  20. Informatic学习总结_day01

热门文章

  1. ZBrush中Tool工具的保存
  2. 安装Oracle 12c及解决遇到的问题
  3. HDU 2078 选课时间( 水题 )
  4. BZOJ 2141 排队 (三维偏序CDQ+树状数组)
  5. [读书笔记] Python数据分析 (二) 引言
  6. C++操作符重载总结operator(小结 更新ing)
  7. java EE使用response返回中文时,出现乱码问题
  8. .get(),eq()的区别
  9. tp volist需要便利两个数组时的处理办法
  10. 微信支付报ip错,怀疑是因为不能正确获取$_Server[addr])ip导致的