Skip to content

Generic using Arithmetic #1528

Closed Answered by angularsen
byzantium0001 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, late reply sorry.
I find generic arithmetic hard, honestly. We have made some attempts to support it: https://github.com/angularsen/UnitsNet/wiki/Experimental:-Generic-Math-and-INumber

The first thing I spot in your example is class Range<T> : IQuantity.
A quantity is Value+Unit, so saying Range is a quantity does not make sense to me.

Generally though, you'll have to provide both TQuantity and TUnit.

Here is a revised example, I didn't test it but at least it compiles. Give it a go and see if it helps.

    public class Range<TQuantity, TUnit>
        where TQuantity : IArithmeticQuantity<TQuantity, TUnit>, IComparable<TQuantity>
        where TUnit : struct, Enum
    {
        public T…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@angularsen
Comment options

Answer selected by angularsen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants