发布网友
共2个回答
热心网友
static Random ran = new Random();
static void Main(string[] args)
{
string filePath = "test.txt";
RandomWrite(filePath);
int min, max;
FindMaxMin(filePath, out min, out max);
Console.WriteLine("Max={0} Min={1}", max, min);
Console.ReadKey();
}
private static void FindMaxMin(string path, out int min, out int max)
{
max = int.MinValue; min = int.MaxValue;
if (!File.Exists(path)) return;
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
using (StreamReader reader = new StreamReader(fs))
while (!reader.EndOfStream)
{
int non = int.Parse(reader.ReadLine().Split(new char[] { },
StringSplitOptions.RemoveEmptyEntries)[1]);
if (non < min) min = non;
if (non > max) max = non;
}
}
static void RandomWrite(string path)
{
int colCount = ran.Next(16, 32);
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write))
using (StreamWriter writer = new StreamWriter(fs))
for (int i = 0; i < colCount; i++)
writer.WriteLine("{0} {1}", ran.Next(2, 128), ran.Next(2, 128));
}
热心网友
uchar i = 0;
WEI=0;
DUAN=0;
TMOD= 0x01;
EA=1;
ET0=1;
TR0=1;
init();
SerialInti();