C#类、结构或接口成员声明中的标记“(”无效
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using
namespace 文件
{
public partial class Form1 : Form
{ int []a=new int [10];
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string path = "aa.txt";
string mystr = "";
FileStream fs = File.OpenRead(path);
StreamReader sr = new StreamReader(fs, Encoding.Default );
//指定打开文件
string str;
int max=0;
while ((str =sr .ReadLine())!=null )
{
mystr = mystr + str + "\r\n"; //\r\n表示回车换行
int t=0;
t=Convert .ToInt16 (str );
if(max<t )
max =t ;
}
sr.Close();
fs.Close();
richTextBox1.Text = mystr;
textBox1 .Text =max.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
Random rdm = new Random();
bool flag;
for (int i = 0; i < 10; i++)
{
while (true)
{
t = rdm.Next(0, 101);
flag = true;
for (int j = 0; j < i - 1; j++)
if (a[j] == t) flag = false;
if (flag == true) break;
}
a[i] = t;
}
int max = 0;
for (int i = 1; i < 10; i++)
{
richTextBox1.Text += a[i].ToString() + "\r\n";
if (max < a[i])
max = a[i];
}
textBox1 .Text = max.ToString();
}
string pa = "aa.txt";
FileStream fr = new FileStream("aa.txt", FileMode.Append);
StreamWriter sr = new StreamWriter(fr, Encoding.Default);
sr.WriteLine( richTextBox1.Text );//C#类、结构或接口成员声明中的标记“(”无效
sr.Close();
fs.Close();
}
}