C#实现详解DataTable的计算功能
using System;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.Data.DataTable table = new DataTable();
//计算常量,可以没有初始化列
object test = table.Compute("1+1", "");
Console.WriteLine(test);
//test=2;
test = table.Compute("1+1", "false");
Console.WriteLine(test);
//test=2;常数计算和filter无关
test = table.Compute("abs(1)", "");
Console.WriteLine(test);
//test=null,不知道为这个什么没有抱错,而且返回null,其他的数学函数都会抱错
test = table.Compute("2%2", "");
Console.WriteLine(test);
//test=0;
//其他函数参考下面的计算列
//初始化datatale
table.Columns.Add("id", typeof(string));
table.Columns.Add("value", typeof(int));
for (int i = 1; i <= 10; i++)
{
System
补充:软件开发 , C# ,