9

In .NET it is not possible to constrain a generic method so it only accepts numeric types as described in the following question: Is there a constraint that restricts my generic method to numeric types?.

But if you look at the reference source for .NET (http://sourceof.net) and look at the source code for the primitive types (Int32, Int64, Single, etc) there is a reference to something called IArithmetic<T> with an implementation of the interface for all primitive types but the implementation has been commented out.

The definition of the interface cannot be found, but looking at the implemented methods the interface defines the required methods for a generic numerics interface.

So my question is: Why was this work abandon?

Community
  • 1
  • 1
svenslaggare
  • 438
  • 4
  • 5
  • duplicate of: http://stackoverflow.com/questions/7241659/iarithmetict-in-net – Daniel A. White Jul 29 '14 at 12:17
  • 1
    @DanielA.White It would allow you to write `public void Add(T a, T b) where T : IArithmetic { return a.Add(b); }` or similar, and has nothing to do with static or not. – Lasse V. Karlsen Jul 29 '14 at 12:18
  • 1
    Emulating the blinding speed of the processor for these operators (a fraction of a CPU cycle for the integral versions) with a virtual interface method call that cannot be inlined does not make anybody happy. Generics are supposed to *improve* perf. – Hans Passant Jul 29 '14 at 12:31

0 Answers0