Notes for heavy-duty operator numbers

Source: Internet
Author: User

// The parameter of the binary operator must be of the include type.
// A parameter must be a class
//-============================================== ========================
Using system;
Using system. Collections. Generic;
Using system. text;

Namespace mystudy
...{
Class Program
...{
Static void main (string [] ARGs)
...{

Result R1 = new result (10, 20 );
Test r2 = new test ();
Result r = R1 + R2;

Console. writeline (R. I );

}

}

Public class result
...{
Public static result operator + (result C1, test C2) // The parameter must be a class
...{
Result T1 = new result (0, 0 );

T1. I = c1. I + c2. I;
T1.j = c1.j + c2.j;

Return T1;
}

Public int I, J;

Public result (int I, Int J)
...{
This. I = I;
This. j = J;

}

}
Public class test
...{
Public int I = 100, j = 200;
}

}

In addition

1. When the comparison operator number is reloaded, it must be reloaded in pairs (= ,! =) (>,<) (>=, <=)
2. The comparison operator must return a value of the bool type.

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.