c# - Problem getting generic extension method to work correctly -


I am trying to create an extension method AddRange for the headset so that I can do something like this:

  var list = new list & lt; Items & gt; (New item), new item (), new item ()}; Var hashset = new hashset & lt; Items & gt; (); Hashset.AddRange (list);  

Here's what I've done so far:

  Public Static Zero AddRange & lt; T & gt; (This icon icon & lt; T & gt; archive, list & lt; T & gt; list) {Foreach (different items in the list) {collection.Add (item); }}  

The problem is, when I try to use the adrenaline, I get this compiler error:

Type arguments for the method 'AddRange & lt; T & gt; (System.Click.Genrich.Collections & lt; T & gt ;, System.CLocks.GenericList.LT; T & gt;) 'can not be estimated using the attempt to clearly specify type arguments Please.

In other words, I should use it instead:

  hashasht.adrenge & lt; Items & gt; (List);  

What am I doing wrong here?

Your code works fine for me:

  System by using. Colllections.Generic; Static class extensions {public static zero AddRange & lt; T & gt; (This iconging & lt; T & gt; archive, list & lt; T & gt; list) {foreach (different items in the list) {collection.Add (item); }}} Class item {} class test {static zero main () {var list = new list> Items & gt; (New item), new item (), new item ()}; Var hashset = new hashset & lt; Items & gt; (); Hashset.AddRange (list); }}  

Can you give a similar short but full program that fails to compile?


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -