Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Created February 15, 2012 14:35
Show Gist options
  • Save ChrisMoney/76ca84bae4b23595ea6e to your computer and use it in GitHub Desktop.
Save ChrisMoney/76ca84bae4b23595ea6e to your computer and use it in GitHub Desktop.
C# --Provides variations of the same function
// 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