日期:2014-05-18  浏览次数:21353 次

c#中怎么清空一个数组
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 = " ";