using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{ public partial class Form1 : Form
{
String[] stuname = new string[4];
int [,] score=new int [4,6];
int stuNum = 0; public Form1()
{
InitializeComponent();
label0.Text = "输入第" + 1 + "个学生:"; } private void button1_Click(object sender, EventArgs e)
{
stuname[stuNum]=textBox0.Text;
score[stuNum, 0] = int.Parse(textBox1.Text);
score[stuNum, 1] = int.Parse(textBox2.Text);
score[stuNum, 2] = int.Parse(textBox3.Text);
score[stuNum, 3] = int.Parse(textBox4.Text);
score[stuNum, 4] = int.Parse(textBox5.Text);
int total = 0;
for (int i = 0; i < score.GetLength(1) - 1; i++)
{
total += score[stuNum , i];
total /= score.GetLength(1) - 1;
score[stuNum, 5] = total;
stuNum++;
label0.Text = "输入第" + (stuNum+1) + "个学生:";
string str="";
//点击输入显示之后 聚焦到textBox0 开始下一位学生成绩的输入
textBox0.Text = " ";
textBox1.Text = " ";
textBox2.Text = " ";
textBox3.Text = " ";
textBox4.Text = " ";
textBox5.Text = " ";
textBox0.Focus();
for (i = 0; i < score.GetLength(0); i++)
{
str += stuname[i] + "\t ";
for (int j = 0; j < score.GetLength(1); j++)
{
str += score[i, j] + "\t "; }
str += "\r\n";
}
textBox6.Text = str;
if (stuNum >= stuname.GetLength(0))
{
textBox0.Enabled = false;
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
textBox4.Enabled = false;
textBox5.Enabled = false;
button1.Enabled = false;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox0.Enabled = true;
textBox1.Enabled = true;
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
button1.Enabled = true;
textBox6.Clear();
String[] stuname = new string[4];
int[,] score = new int[4, 6];
//清空各个文本框
textBox0.Text = " ";
textBox1.Text = " ";
textBox2.Text = " ";
textBox3.Text = " ";
textBox4.Text = " ";
textBox5.Text = " ";
textBox0.Focus(); stuNum = 0;
label0.Text = "输入第 1 个学生:";
} private void button3_Click(object sender, EventArgs e)
{
// 判断是否退出
DialogResult choice;
choice = MessageBox.Show(" 你确定要退出吗?"," ", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (choice == DialogResult.OK)
{
this.Close();
Application.Exit();
}
}
}
}
以上是源码 我的目的是在清空文本框之后 数组也被清空 现在的状态是 第二次输入的时候 只能覆盖掉第一次输入的值 我想在第二次输入的时候 数组的值为0 和第一次输入的时候一样 最最重要的 刚开始学 最好不要太难懂的 谢谢
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{ public partial class Form1 : Form
{
String[] stuname = new string[4];
int [,] score=new int [4,6];
int stuNum = 0; public Form1()
{
InitializeComponent();
label0.Text = "输入第" + 1 + "个学生:"; } private void button1_Click(object sender, EventArgs e)
{
stuname[stuNum]=textBox0.Text;
score[stuNum, 0] = int.Parse(textBox1.Text);
score[stuNum, 1] = int.Parse(textBox2.Text);
score[stuNum, 2] = int.Parse(textBox3.Text);
score[stuNum, 3] = int.Parse(textBox4.Text);
score[stuNum, 4] = int.Parse(textBox5.Text);
int total = 0;
for (int i = 0; i < score.GetLength(1) - 1; i++)
{
total += score[stuNum , i];
total /= score.GetLength(1) - 1;
score[stuNum, 5] = total;
stuNum++;
label0.Text = "输入第" + (stuNum+1) + "个学生:";
string str="";
//点击输入显示之后 聚焦到textBox0 开始下一位学生成绩的输入
textBox0.Text = " ";
textBox1.Text = " ";
textBox2.Text = " ";
textBox3.Text = " ";
textBox4.Text = " ";
textBox5.Text = " ";
textBox0.Focus();
for (i = 0; i < score.GetLength(0); i++)
{
str += stuname[i] + "\t ";
for (int j = 0; j < score.GetLength(1); j++)
{
str += score[i, j] + "\t "; }
str += "\r\n";
}
textBox6.Text = str;
if (stuNum >= stuname.GetLength(0))
{
textBox0.Enabled = false;
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
textBox4.Enabled = false;
textBox5.Enabled = false;
button1.Enabled = false;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox0.Enabled = true;
textBox1.Enabled = true;
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
button1.Enabled = true;
textBox6.Clear();
String[] stuname = new string[4];
int[,] score = new int[4, 6];
//清空各个文本框
textBox0.Text = " ";
textBox1.Text = " ";
textBox2.Text = " ";
textBox3.Text = " ";
textBox4.Text = " ";
textBox5.Text = " ";
textBox0.Focus(); stuNum = 0;
label0.Text = "输入第 1 个学生:";
} private void button3_Click(object sender, EventArgs e)
{
// 判断是否退出
DialogResult choice;
choice = MessageBox.Show(" 你确定要退出吗?"," ", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (choice == DialogResult.OK)
{
this.Close();
Application.Exit();
}
}
}
}
以上是源码 我的目的是在清空文本框之后 数组也被清空 现在的状态是 第二次输入的时候 只能覆盖掉第一次输入的值 我想在第二次输入的时候 数组的值为0 和第一次输入的时候一样 最最重要的 刚开始学 最好不要太难懂的 谢谢
用下面的:Array.Clear(你的数组,0,你的数组.Length);
如果是int型的clear后就全是0
String[] stuname = new string[4];
int [,] score=new int [4,6]; Array.Clear(stuname, 0, stuname.Length);
Array.Clear(score, 0, score.Length);上边是我的数组 下面是用Array.Clear得 按你上边的说法 第一个string数组应该是null值 但是运行不了 无法转换 我用了0 可以清空 不知是否我理解错误你的意思了