Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
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.
1 Answer
- husoskiLv 77 years agoFavorite 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.