Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# implicit operator

    public static implicit operator byte(Digit d) => d.digit;
    public static explicit operator Digit(byte b) => new Digit(b);
Comment

c# implicit operator


XmlBase myBase = new XmlBase();
XElement myElement = myBase;

Comment

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

/// <span class="code-SummaryComment"><summary></span>
/// Creates Currency object from string supplied as currency sign.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="rhs">The currency sign like $,£,¥,€,Rs etc. </param></span>
/// <span class="code-SummaryComment"><returns>Returns new Currency object.</returns></span>
public static implicit operator Currency(string rhs)
{ 
    Currency c = new Currency(0, rhs); //Internally call Currency constructor
    return c;

}

/// <span class="code-SummaryComment"><summary></span>
/// Creates a currency object from decimal value. 
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="rhs">The currency value in decimal.</param></span>
/// <span class="code-SummaryComment"><returns>Returns new Currency object.</returns></span>
public static implicit operator Currency(decimal rhs)
{
    Currency c = new Currency(rhs, NumberFormatInfo.CurrentInfo.CurrencySymbol);
    return c;

/// <span class="code-SummaryComment"><summary></span>
/// Creates a decimal value from Currency object,
/// used to assign currency to decimal.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="rhs">The Currency object.</param></span>
/// <span class="code-SummaryComment"><returns>Returns decimal value of the currency</returns></span>
public static implicit operator decimal(Currency rhs)
{
    return rhs.Value;
}

/// <span class="code-SummaryComment"><summary></span>
/// Creates a long value from Currency object, used to assign currency to long.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="rhs">The Currency object.</param></span>
/// <span class="code-SummaryComment"><returns>Returns long value of the currency</returns></span>
public static implicit operator long(Currency rhs)
{
    return (long)rhs.Value;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: psobject get service name 
Csharp :: how to populate a collection c# 
Csharp :: c# ushort 
Csharp :: in c# show error when user choose old datetime 
Csharp :: how to change font text mesh pro 
Csharp :: .net entities query multiple join condition type inference 
Csharp :: classe padre figlio c# 
Csharp :: select every second row in html table 
Csharp :: handle multiple threads c# 
Csharp :: c# run program as an administrator 
Csharp :: C# How to implement IEnumerable<T interface 
Csharp :: remove multiple element on list from index a to b C# 
Csharp :: mpeg get video size 
Csharp :: asserting exceptions c# 
Csharp :: Fix Array outside the bonus 
Csharp :: unity phone vibration 
Csharp :: linq cheat sheet 
Csharp :: c# use meditor from service 
Csharp :: generate random light color android 
Csharp :: unity 2d top down movement script 
Csharp :: c# zeitverzögerung 
Csharp :: how to clone something as a parent unity 
Csharp :: single or default in c# 
Csharp :: c# ef dynamic ApplyConfiguration 
Csharp :: AR light estimation Unity 
Csharp :: dispathcer in wpf stack overflow 
Csharp :: unity 3d animator live link 
Csharp :: add-users:430 Uncaught TypeError: $(...).validate is not a function 
Csharp :: check for held hey unity 
Csharp :: unity on statement how 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =