C # understand the Operator

Source: Internet
Author: User
The system internal creation type supports some internal creation parameters. For example, an int can be converted into a double type.
Then, how do we define the category or structure defined by ourselves as the specified category?
In the following example When example. myintmethod (lunch) method is used, Example. the metric value of the myintmethod method is int type, but the actual metric value is hour. At this time, you need to modify the metric value, the sequence operator method uses the sequence operator in the hour structure. Struct Hour
{
Public   Int Ivalue;
// Structured Data
Public Hour ( Int Initialvalue)
{
This . Ivalue = Initialvalue;
}
///   <Summary>
///  Xiaoming's attention OperatorAllows a hour to convert an image into an int.
///   </Summary>
///   <Param name = "from"> Number of records of the type that requires parameter Encoding </Param>
///   <Returns> </returns>
/* Note:
When specifying the operator, the source type must be identified as a metric (hour in this example)
Object Type indicates the type name sequence after the operator (INT in this example). do not specify the return type before the operator.
When you declare your own operator, you must specify them as linear operator or linear operator. Use implicit and exlpicit to specify
*/
Public   Static   Implicit   Operator   Int (Hour from)
{
Return From. ivalue;
}
}

// Define a category
Class Example
{
Public   Static   Void Myintmethod ( Int Parameter)
{
}
}

Static   Void Main ( String [] ARGs)
{
Hour lunch =   New Hour ( 12 );
// Example. the metric value of the myintmethod method must be int type, but the actual metric value must be hour, the sort operator method uses the sort operator in the hour structure.
//Simplified Linear Regression , Convert lunch into int type
Example. myintmethod (lunch );
}

At that time, when should we be clear as a legal model and when should we be clear as a legal model?
If your website is always secure and has no loss of information, and cannot be used frequently, you can refer to this website as an attack type. Otherwise, it should be noted that the instructor should.

In order to better understand the operator, let's look at the following example: Class Program
{
/*
* In this example, we set only the operator "hour + hour" to "re-attention. However, there is no fixed homur + Int or Int + hour operator.
* However, we have defined a regression operator. When hour + int and INT + hour are used in the regression operator, the optimize hour operator converts the int type into hour.
*/
Struct Hour
{
Private   Int Ivalue;
Public Hour ( Int Initialvalue)
{
This . Ivalue = Initialvalue;
}
// Specify the cognominal operator as hour + hour.
Public   Static Hour Operator   + (Hour LHS, hour RHs)
{
Return   New Hour (LHS. ivalue + RHS. ivalue );
}
// Xiaoming operator, which converts int type into hour
Public   Static   Implicit   Operator Hour ( Int From)
{
Return   New Hour (from );
}
}

Static   Void Main ( String [] ARGs)
{
// Actual hour variation
Hour LHS =   New Hour ( 2 );
// Actual hour variation B
Hour RHS =   New Hour ( 3 );
// The distinct operator is used. At this time, both LHS and RHS are hour
Hour hrsum = LHS + RHS;
// The weight operator is used, and the weight operator is used. Because 11 is of the int type, but in the actual example, the portable data is hour, and the required parameter is used.
Hour hrsumint = LHS +   11 ;
// The weight operator is used, and the weight operator is used. Because 15 is of the int type, the actual number of bytes imported into the example is hour.
Hour hrsumint =   15   + RHS;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.