what is implicit keyword c#
//Ability to assign a non-primitive instance a certain value,
//and to assign a primitave from the object
//Usage example:
Currency c = 10.5;
double myMoneyAmount = c;
//Also can further more do:
c = "$";
string currencyType = c;
//Impl example
///
/// Creates Currency object from string supplied as currency sign.
///
///
///
public static implicit operator Currency(string rhs)
{
Currency c = new Currency(0, rhs); //Internally call Currency constructor
return c;
}
///
/// Creates a currency object from decimal value.
///
///
///
public static implicit operator Currency(decimal rhs)
{
Currency c = new Currency(rhs, NumberFormatInfo.CurrentInfo.CurrencySymbol);
return c;
///
/// Creates a decimal value from Currency object,
/// used to assign currency to decimal.
///
///
///
public static implicit operator decimal(Currency rhs)
{
return rhs.Value;
}
///
/// Creates a long value from Currency object, used to assign currency to long.
///
///
///
public static implicit operator long(Currency rhs)
{
return (long)rhs.Value;
}