C# IDictionary排序

代码阐释:我这里是取奖金支给率的排序(正序/倒叙),通过指定的公式得到tempa,tempb,tempc插入到IDictionary中.此逻辑有些乱,但是最终实现了我想要的效果,下面是我的代码及效果图.

				IDictionary<string, decimal> dic = new Dictionary<string, decimal>();
				decimal tempa = 0;
				if (E1 != 0 || A1 != 0)
				{
					tempa = Convert.ToDecimal(E1 / A1);
				}
				decimal tempb = 0;
				if (E2 != 0 || A2 != 0)
				{
					tempb = Convert.ToDecimal(E2 / A2);
				}
				decimal tempc = 0;
				if (E3 != 0 || A3 != 0)
				{
					tempc = Convert.ToDecimal(E3 / A3);
				}
				dic.Add("GLB", tempa);
				dic.Add("SJB", tempb);
				dic.Add("JXB", tempc);
				List<Dictionary<string, decimal>> listDict = new List<Dictionary<string, decimal>>();
				Dictionary<string, decimal> dict = new Dictionary<string, decimal>();
				var dicSort = from objDic in dic orderby objDic.Value descending select objDic;//倒叙
				//var dicNew = dic.OrderBy(s1 => s1.Value);//正序
				foreach (KeyValuePair<string, decimal> kvp in dicSort)
				{
					dict.Add(kvp.Key, kvp.Value);
					listDict.Add(dict);
				}
				var keys = listDict[0].Keys;
				List<TestClass> list = new List<TestClass>();
				foreach (var key in keys)
				{
					TestClass test = new TestClass();
					test.BM = key;
					list.Add(test);
				}
				var bm1 = list[0].BM;
				var bm2 = list[1].BM;
				var bm3 = list[2].BM;
				#region  bm1
				if (bm1 == "GLB")
				{
					sheetAt.GetRow(4).GetCell(12).SetCellValue(1);
				}
				if (bm1 == "SJB")
				{
					sheetAt.GetRow(5).GetCell(12).SetCellValue(1);
				}
				if (bm1 == "JXB")
				{
				}
				#endregion
				#region  bm2
				if (bm2 == "GLB")
				{
					sheetAt.GetRow(4).GetCell(12).SetCellValue(2);
				}
				if (bm2 == "SJB")
				{
					sheetAt.GetRow(5).GetCell(12).SetCellValue(2);
				}
				if (bm2 == "JXB")
				{
					sheetAt.GetRow(6).GetCell(12).SetCellValue(2);
				}
				#endregion
				#region  bm3
				if (bm3 == "GLB")
				{
					sheetAt.GetRow(4).GetCell(12).SetCellValue(3);
				}
				if (bm3 == "SJB")
				{
					sheetAt.GetRow(5).GetCell(12).SetCellValue(3);
				}
				if (bm3 == "JXB")
				{
					sheetAt.GetRow(6).GetCell(12).SetCellValue(3);//应发奖金支给率排名
				}
				#endregion

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值