Omri Turgeman Omri Turgeman - 1 month ago 10
C# Question

Pass any type of list to another class

I'm building a dynamic search form and I want to send a list to the search form class (any type of list). I've searched here and i didn't find any answer.

First Class:



public class myfirstclass
{
Search search = new Search(List<anyType>);
search.show()
}


search form class:



public partial class Search : Form
{
public search(list<anytype> mylist)
{
}
}

Answer

You can change the constructor parameter to accept an IList instead:

List<Foo> somelist = new List<Foo>();
Search search = new Search(somelist);

public partial class Search : Form
{
    public Search(IList mylist)
    {
    }
}
Comments