How do I override ToString() and implement generic?

前端 未结 4 1292
温柔的废话
温柔的废话 2021-01-16 09:33

I have code that I want to make the following changes:

  1. How do I override ToString()? It says: A static member ...ToString(System.Collections.Generic.List)\'

4条回答
  •  天命终不由人
    2021-01-16 10:18

    You cannot use extension methods to override an existing method.

    From the spec http://msdn.microsoft.com/en-us/library/bb383977.aspx

    "You can use extension methods to extend a class or interface, but not to override them. An extension method with the same name and signature as an interface or class method will never be called. At compile time, extension methods always have lower priority than instance methods defined in the type itself."

提交回复
热议问题