How to call a method overload based on closed generic type?

后端 未结 6 2017
时光取名叫无心
时光取名叫无心 2021-02-13 10:20

Suppose I have three methods:

void Foo(MemoryStream v) {Console.WriteLine (\"MemoryStream\");}
void Foo(Stream v)       {Console.WriteLine (\"Stream\");}
void Fo         


        
6条回答
  •  生来不讨喜
    2021-02-13 11:08

    default(T) will always return null when type T is of reference type and will return zero if T is of numeric value types.

    So at any time its not returning an object using which you can call your overloaded version of Foo methods.

    So Short answer you cant do this, you have to find out other ways to call overloaded methods.

提交回复
热议问题