C# Generics: If T is a return type, can it also be void? How can I combine these interfaces together?

前端 未结 2 1082
粉色の甜心
粉色の甜心 2021-01-03 20:57

I have the following interface that returns the generic parameter of type T using a callback...

public interface IDoWork
{
    T DoWork();
}
         


        
2条回答
  •  一整个雨季
    2021-01-03 21:11

    Unfortunately, they can't be combined.

    You can see this in the framework - that's why there is a separate Task and Task class, for example.

    That being said, you can often share implementations in this type of scenario by using IDoWork and passing null for values, etc.

    提交回复
    热议问题