不好意思,把那些给忘记了,
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int n = 0;
if (textBox1.Text != "")
{
string a = textBox1.Text;
string[] charsa = new string[] { "," };
string[] temp = a.Split(charsa, StringSplitOptions.None);
string s = "";
for (int i = 0; i < temp.Length; i++)
{
try
{
Single te = Convert.ToSingle(temp[i]);
}
catch (Exception ex)
{
s += temp[i] + ",";
//捕捉到异常的情况时就把他们连接到一起
n += 1;
}
}
if (n == 0) //都是正确的数字
{
Single tempt = 0;
for (int i = 0; i < temp.Length; i++)
{
tempt +=Convert.ToSingle( temp[i]);
}
textBox3.Text = "平均值是:"+tempt / temp.Length;
tempt = Convert.ToSingle(temp[0]);
for (int i = 1; i < temp.Length; i++)
{
if (tempt < Convert.ToSingle(temp[i]))
{
tempt = Convert.ToSingle(temp[i]);
}
}
textBox2.Text = "最大值是:" + tempt;
}
else
{
textBox4.Text = "您输入的" + s.Substring(0, s.Length - 1) + "不是数字 ,请输入正确的数字!";
textBox1.Text = "";
}
}
else
{
MessageBox.Show("请输入需要计算的数字!");
}
}
}
}