문제

Just out of curiosity I was trying to find the relevant operator overloads for unary operators like +,-,* etc. for Int32 in MsCorLib.dll

I use ILSpy.

When I checked the System.Int32 struct definition, I could not see any operator overloading related.

Q: Do I look at the wrong place -then where should I look to see operator overloads for primitive types- or I should not even expect to see those methods?

도움이 되었습니까?

해결책

The operators are part of C# and defined in the C# Language Specification.

Example:

7.7.2 Unary minus operator

[...] The predefined negation operators are:

  • Integer negation:

    int operator –(int x);
    long operator –(long x);
    

    The result is computed by subtracting x from zero. [...]

  • Floating-point negation:

    float operator –(float x);
    double operator –(double x);
    

    The result is the value of x with its sign inverted. If x is NaN, the result is also NaN.

  • Decimal negation:

    decimal operator –(decimal x);
    

    The result is computed by subtracting x from zero. Decimal negation is equivalent to using the unary minus operator of type System.Decimal.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top