形参有默认值,表是该参数可以传,可以不传。

例如:

 

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;
}

 运行结果:

C# 形参中有默认值

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-12-09
  • 2021-08-24
  • 2021-06-15
  • 2022-02-11
猜你喜欢
  • 2021-05-28
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2021-06-02
相关资源
相似解决方案