var d = from d1 in pDT1.AsEnumerable() from d2 in pDT2.AsEnumerable() where d1.Field<string>("ID") == d2.Field<string>("ID") select new { a = d1.Field<string>("ID"), v = d1.Field<double>("VALUE") * d2.Field<double>("VALUE") }; var d = pDT1.AsEnumerable().Join(pDT2.AsEnumerable(), s => s.Field<string>("ID"), sc => sc.Field<string>("ID"), (s, sc) => new { a = s.Field<string>("ID"), v = s.Field<double>("VALUE") * sc.Field<double>("VALUE") });
例子,三个DataTable之间的运算
var d = pDT1.AsEnumerable().Join(pDT2.AsEnumerable(), s => s.Field<string>("ID"), sc => sc.Field<string>("ID"), (s, sc) => new { a = s.Field<string>("ID"), v = s.Field<double>("VALUE") * sc.Field<double>("VALUE") }); DataTable pDT3 = pGetDT(); foreach (var l in d) { DataRow pDR = pDT3.NewRow(); pDR[0] = l.a; pDR[1] = l.v; pDT3.Rows.Add(pDR); Console.WriteLine("{0} {1}", l.a, l.v); } var E = from d1 in d from d2 in pDT1.AsEnumerable() where d1.a == d2.Field<string>("ID") select new { a = d1.a, v = Convert.ToDouble( d1.v) - d2.Field<double>("VALUE") }; foreach (var l in E) { Console.WriteLine("{0} {1}", l.a, l.v); } Console.ReadLine();
作者:
cglnet
本文版权归cglNet和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.