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 :: c# get size of file 
Csharp :: how to get the path of the current directory in c# 
Csharp :: includes method C# 
Csharp :: c# string to enum 
Csharp :: how to check the distance between two dates c# 
Csharp :: unity3d change player position 
Csharp :: c# solution path 
Csharp :: Editor log location unity 
Csharp :: bubble sort in c# 
Csharp :: c# read file from path 
Csharp :: Xamarin.Forms - How to navigate to a tabbed page child page 
Csharp :: json to httpcontent c# 
Csharp :: get waht is differnt between two arrays c# 
Csharp :: C# .NET Core linq Distinct 
Csharp :: start command line from c# 
Csharp :: fluentassertions force exceptions 
Csharp :: c# palidrone 
Csharp :: c# linq remove duplicate items from list of integer 
Csharp :: create char array c# 
Csharp :: c# afficher texte 
Csharp :: where is c# used 
Csharp :: c# read binary file 
Csharp :: c# get month number 
Csharp :: change sprite of a sprite unity 
Csharp :: c# listbox delete selected items 
Csharp :: javascript close page after 5 seconds 
Csharp :: how get query from url in laravel 
Csharp :: list removeall unity 
Csharp :: c# read file 
Csharp :: c# string remove 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =