形參有默認值,表是該參數可以傳,可以不傳。
例如:
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; }
運行結果: