C#月份和日期转大写和C#集合分组
//日转化为大写 private static string DaytoUpper(int day, string type) { if (day < 20) { return MonthtoUpper(day, "") + type; } else { String str = day.ToString(); if (str[1] == '0') { return NumtoUpper(Convert.ToInt16(str[0].ToString())) + "十" + type; } else { return NumtoUpper(Convert.ToInt16(str[0].ToString())) + "十" + NumtoUpper(Convert.ToInt16(str[1].ToString())) + type; } } } //月转化为大写 private static string MonthtoUpper(int month, string type) { if (month < 10) { return NumtoUpper(month) + type; } else if (month == 10) { return "十" + type; } else { return "十" + NumtoUpper(month - 10) + type; } } private static string NumtoUpper(int num) { String str = num.ToString(); string rstr = ""; int n; for (int i = 0; i < str.Length; i++) { n = Convert.ToInt16(str[i].ToString());//char转数字,转换为字符串,再转数字 switch (n) { case 0: rstr = rstr + "〇"; break; case 1: rstr = rstr + "一"; break; case 2: rstr = rstr + "二"; break; case 3: rstr = rstr + "三"; break; case 4: rstr = rstr + "四"; break; case 5: rstr = rstr + "五"; break; case 6: rstr = rstr + "六"; break; case 7: rstr = rstr + "七"; break; case 8: rstr = rstr + "八"; break; default: rstr = rstr + "九"; break; } } return rstr; }
C#集合分组:
var _lstMonthGroup = _logInfoList.GroupBy(x => x.month); string _strJson = string.Empty; _strJson += "["; foreach (IGrouping<string, LogInfo> _monthData in _lstMonthGroup) { _strJson += "{ "; _strJson += "\"moth\":\"" + _monthData.Key + "\","; _strJson += "\"mothData\":["; //按天分组 var _lstDayGroup = _monthData.GroupBy(c => c.monthAndday).ToList(); foreach (var _dayData in _lstDayGroup) { _strJson += "{"; _strJson += "\"dayName\":\"" + _dayData.Key + "\","; _strJson += "\"dayDta\":["; foreach (var vv in _dayData) { _strJson += "{"; _strJson += "\"detial\":\"" + vv.detial + "\""; _strJson += "},"; } _strJson = _strJson.TrimEnd(','); _strJson += "]"; _strJson += "},"; } _strJson = _strJson.TrimEnd(','); _strJson += "]"; _strJson += "},"; } _strJson = _strJson.TrimEnd(','); _strJson += "]";