C# 控制台 我时时监测,从60个数取最大的存库表里,依次一天里最大,月,年最大保存到对应4张表里
string a = "";
int i = 0;
while (true)
{
//这是内存使用率 string lv = PcInfoVal.RamVal().ToString();
string lv1 = PcInfoVal.RamTotal().ToString();
if (i == 0)
{
a = lv;
}
else {
a += "," + lv;
}
i++;
这是一分钟里取最大的 请问一天一月一年的应该怎么写
if (i == 60) {
TimeMonitorModel model = new TimeMonitorModel();
TimeMonitorBLL bll = new TimeMonitorBLL();
string rs = getMax(a);
model.MonitorTime = DateTime.Now;
model.RamValue = Int32.Parse(rs);
bll.Add(model);
i = 0;
a = "";
}
Console.WriteLine(lv + "/" + lv1);
Thread.Sleep(1000);
}
}
后面取最大的数
public string getMax(string a) {
string[] b;
b = a.Split(',');
int[] c = new int[b.Length];//这一步难
for (int i = 0; i < b.Length; i++)
{
c[i] = Convert.ToInt32(b[i]);
}
for (int m = 0; m < b.Length; m++)
{
for (int n = m + 1; n < b.Length; n++)
{
if (c[m] > c[n])
{
int t = c[m];
c[m] = c[n];
c[n] = t;
}
}
}
//Console.WriteLine();
//Console.WriteLine("最小值是" + c[0]);
//Console.WriteLine("最大值是" + c[b.Length - 1]);
return c[b.Length - 1].ToString();
}