Auto cast generic class to his parameter T

Hello everyone :smile:

I was wondering if it was possible to have a class like this :

public class MyGeneric<T>
{
    private T value;
    public T Value => value;
}

And use it like this :

private MyGeneric<float> myValueA;
private float myValueB;

void DoSomething()
{
    myValueA += myValueB;
}

But without having to handle all custom operators
Literraly considering MyGeneric as T everytime then assign the operations’s result in the value field :slight_smile:

It would be a life saver for me, thanks in advance !

You probably want this: User-defined explicit and implicit conversion operators - provide conversions to different types - C# reference | Microsoft Learn

You are my man