calling an overloaded method in generic method

后端 未结 5 1654
日久生厌
日久生厌 2021-01-12 23:18
class Test
{
    public BinaryWriter Content { get; private set; }
    public Test Write (T data)
    {
        Content.Write(data);
        return this;
           


        
5条回答
  •  心在旅途
    2021-01-13 00:14

    You can't do that.

    Since real type of T is unknown at compile-time, compiler can't find appropriate Write overload, and tries to call the first found one. There is no overload, which could be called with any type of T (e.g., Write(object)).

提交回复
热议问题