Created
February 15, 2012 14:35
-
-
Save ChrisMoney/76ca84bae4b23595ea6e to your computer and use it in GitHub Desktop.
C# --Provides variations of the same function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Default Arguments Example | |
// FunctionWithDefaltArgments – provide variations of the same function, some with default //arguments, by overloading the function name | |
using System; | |
namespace FunctionsWithDefaultArguments | |
{ | |
public class program | |
{ | |
public static void Main(string[] args) | |
{ | |
// access the member function | |
Console.WriteLine”(0)”. DisplayRoundedDecimal (12.345678M, 3)); | |
// wait for user acknowledge | |
Console.WriteLIne(“Press enter to terminate…”); | |
Console.Read(); | |
} | |
// DisplayRoundDecimal – convert a decimal value into a string with the specified number of significant //digits | |
public static string DisplayRoundedDecimal (decimal, mValue, int nNumberOfSignificantDigits) | |
{ | |
// first round the number off to the specified number of significant digits | |
decimal mRoundedValue = decimal.Round(mValue, nNumberOfSignificantDigits); | |
// convert that to a string | |
string s = Convert.ToString(mRoundValue); | |
return s; | |
} | |
public static string DisplayRoundedDecimal (decimal mValue) | |
{ | |
// invoke DisplayRoundedDecimal (decimal, int) specifying the default number of digits | |
string s = DisplayRoundedDecimal (mValue, 2); | |
return s; | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment