c# - Overload generic List's Add with extension method -


I would like to overload the add link of a generic list so that I can use the archive initialization: < Pre> var x = new list & lt; Tupal & lt; String & gt; & Gt; {{"1", "2"}, {"1", "2"}};

(Where Google is a simple custom implementation of a binary Tupal.) However, I created an extension method, put the instruction used in the CS file and still "no surcharge No "method" takes "2 arguments" panic ". Is it not possible (with extension method)?

Extension method code:

  Namespace extensions rule {public static class extension {add public static zeros < T & gt; (This list is & lt; Tupal & lt; T & gt; Self, T value 1, T value 2) {self.Add (New Tupal & lt; T> {value1, value2}); }}    

allows the use of the Microsoft extension extension in C # 6.0 [0] Is early collection of Hurray :)

And since it is not a .NET Framework or CLR change, but there is a compiler change, this feature can be used with .NET 4.0.

The following is now valid C # code (tested in Visual Studio 2015 RC)

  class program {static zero main (string [] args) { Var x = new list & lt; Tupal & lt; String, string & gt; & Gt; {{"1", "2"}, {"1", "2"}}; }} Public static class extensions {add public static zeroes < T1, T2 & gt; (The list & lt; Tuple & lt; T1, T2 & gt; & gt; self, T1 value1, T2 value2) {self.Add (Tuple.Create (value1, value2)); }}   

[0]

Comments