C# 类方法的调用!急!在线等!

来源:百度知道 编辑:UC知道 时间:2024/06/06 02:38:36
class Array
{
public double Methods(double x, double y, Int32 i)
{
double a = 0;
switch (i)
{
case 0:
a = x * y;
break;
case 1:
a = x + y;
break;
case 2:
a = (x * y) / 2;
break;
case 3:
if (x > y)
{
a = x;
}
else
{
a = y;
}
break;
}
return a;
}

protected void Button1_Click(object sender, EventArgs e)
{
}
我现在要如何调用这些方法啊!? 我拖了TextBox1和TextB

protected void Button1_Click(object sender, EventArgs e)
{
try{
int x = int.Parse(this.TextBox1.Text);
int y = int.Parse(this.TextBox2.Text);
this.Label1.Text = Methods(x, y, 0).ToString();
}
catch
{
MessageBox.show("只能输入数值");
}
}

int x = int.Parse(TextBox1.Text);
int y = int.Parse(TextBox2.Text);
再加个给I赋值
int i=int.Parse(TextBox3.Text);

Label1.Text=Methods(x, y, i).ToString();

注意大小写

顶楼上~TRY{}
catch{}