c# - How to create an extension method for ToString? -


i have tried this:

public static class listhelper {     public static string tostring<t>(this ilist<string> list)     {         return string.join(", ", list.toarray());     }      public static string tostring<t>(this string[] array)     {         return string.join(", ", array);     } } 

but not work, both string[] , list<string>. maybe need special annotations?

extension methods checked if there no applicable candidate methods match. in case of call tostring() there always applicable candidate method, namely, tostring() on object. purpose of extension methods extend set of methods available on type, not override existing methods; that's why they're called "extension methods". if want override existing method you'll have make overriding method.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -