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

threemax为什么是并非所有都有返回值?
namespace experience312
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

  int k = 0;
  class student
  {
  public string ne; double nr; public double em; public double mm; public double cm;
  public double Nr { get { return nr; } set { if(value<0) nr=0;else nr=value;} }
  public student(string nn, double n, double e, double m, double c) { this.ne = nn; this.nr = n; em = e; mm = m; cm = c; }
  public double answer() { return em + mm + cm; }
  }

  class studentlist
  {
  private student[] Tom = new student[5];

  public student this[int index]
  {
  get
  {
  if (index < 0 || index >= 5)
  return Tom[0];
  else return Tom[index];
  }
  set
  {
  if (index < 0 || index >= 5)
  Tom[0] = value;
  else
  Tom[index] = value;
  }
  }

  public string threeMax(int u, student[] number)
  {

  double t=0;
  for (int z = 0; z <= u; z++)
  {
  for (int g = 1; g <= u; g++)
  {
  if (number[z].cm <= number[g].cm)
  {
  t = number[g].cm;
  number[z].cm = number[u].cm;
  number[u].cm = t;
  return number[0].ne;
  }
  else { return number[0].ne; }
  }
  }


  }


  }
   
  studentlist Internet = new studentlist();
  private void button1_Click(object sender, EventArgs e)
  {
  string a = Convert.ToString(textBox1.Text);
  double b = Convert.ToDouble(textBox3.Text);
  double c = Convert.ToDouble(textBox3.Text);
  double d = Convert.ToDouble(textBox4.Text);
  double f = Convert.ToDouble(textBox5.Text);
   
  Internet[k] = new student(a, b, c, d,f);
  k++;
  label9.Text = "已经添加了" + k + "个学生信息!";
   
  }

  private void button2_Click(object sender, EventArgs e)
  {
  string g=Convert.ToString(textBox6.Text);
  for (int i = 0; i <= k-1; i++) { 
  if (Internet[i].ne ==g) 

  {label1.Text = Convert.ToString(Internet[i].answer());}
   
  }
  }

   

   


------解决方案--------------------
你应该考虑到如果u=0,循环不起来,那么你是没有返回值的,改成如下试试
C# code

public string threeMax(int u, student[] number)
        {

            double t