What is the usage of floating-point numbers in C# in this example. Why is it necessary? Please see example below. Thank you.?

public static BankAccount openBankAccount(string owner, double balance)
{
return openBankAccount(owner, balance, 0.0);
}
public static BankAccount openBankAccount(string owner)
{
return openBankAccount(owner, 0.0);
}

0.0 is a floating-point number. But why is it there? Like owner is owner, balance is balance, but 0.0 has nothing in "public static BankAccount openBankAccount" defining it.

husoski2014-04-03T15:36:58Z

Favorite Answer

Who knows? If that even compiles, then there's a (string, double, double) overload of that method that you're not showing. That's where you look for what that 0.0 is supposed to mean. It's what that overload does with its third parameter.

But what's this all about, anyway? C# supports default parameters so you don't need to have so many overloads. The three argument version could have been:

public static BankAccount openBankAccount( string owner, double balance=0.0, double mystery=0.0)
{
... body of mystery method
}

...and you would get the same effect as those three overloads.