C#的学习笔记

两种循环方法

 List list = new List();
 List listString = new List();
foreach (DataRow dr in dt.Tables[0].Rows)
            {
                string mddj = dr["mdid"].ToString().Trim() + dr["djid"].ToString().Trim();
                if (!list.Contains(mddj))
                {
                    list.Add(mddj);
                }
            };
            foreach (string eachString in list)
            {
                string md = eachString.Substring(0, 2);
                string dj = eachString.Substring(2);
                DataRow[] dr = dt.Tables[0].Select("mdid='" + md + "' and djid = '"+dj+"'");

                DataTable dtt_single = dr[0].Table.Clone();  // 复制DataRow的表结构
                foreach (DataRow row in dr)
                {
                     dtt_single.ImportRow(row);
                     dtt_single.Rows.Add(row);  // 将DataRow添加到DataTable中
                }

var dtt_single = dt.Tables[0].Where(row => row.Field("mdid").Equals(md) && row.Field("djid").Equals(dj));
dtt_single.TableName = eachString;
ds_all.Tables.Add(dtt_single);
            }

对象写法

  dataJson.forEach(function (v, i) {
              barData[v.mdid + v.djid] = {};
              barData[v.mdid + v.djid]["TotalCount"] = v.TotalCount;
              barData[v.mdid + v.djid]["BCount"] = v.BCount;
              barData[v.mdid + v.djid]["CurrCount"] = v.CurrCount;
              barData[v.mdid + v.djid]["djname"] = $.trim(v.djname);
           })
 for (var item in barData) {
          barDataArr.push(barData[item]);
           }
 barDataArr.sort(function (a, b) {
          return b["TotalCount"] - a["TotalCount"];
         })
 xAxis = Object.keys(barData)

你可能感兴趣的:(C#的学习笔记)