形参有默认值,表是该参数可以传,可以不传。
例如:
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text += div(1, 3, 5).ToString() + " | ";
textBox2.Text += div(1, 13).ToString();
}
private double div(double value1, double value2, int digits=15)
{
if (value2 == 0.0)
{
return 0;
}
Decimal dm1 = new Decimal(value1);
Decimal dm2 = new Decimal(value2);
decimal fdsd = Decimal.Divide(dm1, dm2);
double dret = Convert.ToDouble(fdsd);
if (digits != 16)
{
dret = Math.Round(dret, digits);
}
return dret;
}
运行结果: