0

I am trying to implement a value type generic method and a reference type generic method with empty parameters of the same name. But I cannot found solution for this problem.

Example of the code I've tried:

class A<T> where T : struct
{
    public static A Instance { get; } = new A();

    public void Add(T item)
    {

        ...
    }

    ...
}

class B<T> where T : class
{
    public static B Instance { get; } = new B();

    public void Add(T item)
    {

        ...
    }

    ...
}

class C
{
    public void Add(T item) where T : struct => A.Instance.Add(item);
    public void Add(T item) where T : class => B.Instance.Add(item);

    ...
}

How can I overload generic method in C# in this case?

Thank you.

0 Answers0