code for varience in generic types in C#

Vivek.Ramapuram
Posted by Vivek.Ramapuram under C# category on | Points: 40 | Views : 276
class Program
{
public class VarianceWork
{
public static void AddItem<I, L>(List<I> item, List<L> list)
where I : L
{
foreach (I newItem in item)
{
list.Add(newItem);
Console.WriteLine("Added");
}
}
}

static void Main()
{
List<int> li = new List<int>();
li.Add(1);
li.Add(2);
List<object> obj = new List<object>();

VarianceWork.AddItem<int, object>(li, obj);
}
}

Comments or Responses

Login to post response