2 个解决方案
#1
int minAccountLevel = int.MaxValue;
int maxAccountLevel = int.MinValue;
foreach (DataRow dr in table.Rows)
{
int accountLevel = dr.Field<int>( "AccountLevel");
minAccountLevel = Math.Min(minAccountLevel, accountLevel);
maxAccountLevel = Math.Max(maxAccountLevel, accountLevel);
}
这样应该可以换成变量的
int maxAccountLevel = int.MinValue;
foreach (DataRow dr in table.Rows)
{
int accountLevel = dr.Field<int>( "AccountLevel");
minAccountLevel = Math.Min(minAccountLevel, accountLevel);
maxAccountLevel = Math.Max(maxAccountLevel, accountLevel);
}
这样应该可以换成变量的
#2
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("name", typeof(int)),
new DataColumn("value", typeof(int))});
dt.Rows.Add(new object[] { 1, 2 });
dt.Rows.Add(new object[] { 2, 12 });
dt.Rows.Add(new object[] { 3, 16 });
String field = "value";
Object t = dt.Compute("max(" + field + ")", "");
MessageBox.Show(t.ToString());
t = dt.Compute("min(" + field + ")", "");
MessageBox.Show(t.ToString());
t = dt.Compute("avg(" + field + ")", "");
MessageBox.Show(t.ToString());
#1
int minAccountLevel = int.MaxValue;
int maxAccountLevel = int.MinValue;
foreach (DataRow dr in table.Rows)
{
int accountLevel = dr.Field<int>( "AccountLevel");
minAccountLevel = Math.Min(minAccountLevel, accountLevel);
maxAccountLevel = Math.Max(maxAccountLevel, accountLevel);
}
这样应该可以换成变量的
int maxAccountLevel = int.MinValue;
foreach (DataRow dr in table.Rows)
{
int accountLevel = dr.Field<int>( "AccountLevel");
minAccountLevel = Math.Min(minAccountLevel, accountLevel);
maxAccountLevel = Math.Max(maxAccountLevel, accountLevel);
}
这样应该可以换成变量的
#2
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("name", typeof(int)),
new DataColumn("value", typeof(int))});
dt.Rows.Add(new object[] { 1, 2 });
dt.Rows.Add(new object[] { 2, 12 });
dt.Rows.Add(new object[] { 3, 16 });
String field = "value";
Object t = dt.Compute("max(" + field + ")", "");
MessageBox.Show(t.ToString());
t = dt.Compute("min(" + field + ")", "");
MessageBox.Show(t.ToString());
t = dt.Compute("avg(" + field + ")", "");
MessageBox.Show(t.ToString());