标签:log reac odata kpi pre end name lambda表达式 add
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
public class TestOne
{
private const string column = "A,B,C,D,E";
DataTable dt = new DataTable();
List<KPIFormula> list = new List<KPIFormula>();
private List<KPIFormula> log;
public List<KPIFormula> Test()
{
//添加列
dt.Columns.AddRange(column.Split(‘,‘).Select(x => new DataColumn(x)).ToArray());
//继续添加新列
List<string> addcols = new List<string>() { "F","G","H","I","J"};
addcols.ForEach(x => dt.Columns.Add(x));
int k = 0;
for (int i = 0; i < 5; i ++)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < 10; j++)
{
dr[j] = k++;
}
dt.Rows.Add(dr);
}
//降序
DataTable dtorder = dt.AsEnumerable().OrderByDescending(o => o["A"]).CopyToDataTable();
//lambda过滤
List<string> pre = dt.AsEnumerable().Where(w => w.Field<string>("A").Contains("0") && w.Field<string>("B").Contains("1")).Select(w => w.Field<string>("C")).Distinct().ToList();
list = dt.AsEnumerable().Select(o =>
{
return new KPIFormula()
{
subject = o["A"].ToString(),
name = o["B"].ToString(),
formula = o["C"].ToString()
};
}).ToList();
//对数据做一些处理
TestTwo(ref list);
return list;
}
public List<KPIFormula> TestTwo(ref List<KPIFormula> kpilist)
{
if (log == null)
{
log = new List<KPIFormula>();
int flag = 0;
kpilist.ForEach(c =>
{
if (c == null) return;
var item = new KPIFormula
{
subject = c.subject + flag,
name = c.name + flag,
formula = c.formula + flag
};
log.Add(item);
flag++;
});
}
kpilist = log;
return kpilist;
}
}
//定义KPIFormula对象集
public class KPIFormula
{
public string subject { set; get; }
public string name { set; get; }
public string formula { set; get; }
}
}
标签:log reac odata kpi pre end name lambda表达式 add
原文地址:https://www.cnblogs.com/dongleifun/p/13047222.html