Generic Method - Cannot implicitly convert type 'string' to T

前端 未结 4 1294
后悔当初
后悔当初 2021-01-15 04:41

May be a simple question..

I have an interface:

public interface ISanitizer
{
    T Sanitize(T data_);
}

And an implementi

4条回答
  •  悲&欢浪女
    2021-01-15 05:35

    Your problem is that the method Sanitize hasTas the return type, but the method actually returns astringfromRegex.Replace`.

    Try changing the method to return a string instead:

    public virtual string Sanitize(T filename_)
    

    That means you need to change your method in the interface to return string as well.

提交回复
热议问题