Dynamically Pass List of Object As A Parameter

Viewed 4275

I've a method where I pass list of object as the following:

public void BindGridView(int pageIndex, List<Users> lstUsers, GridView grd, Panel pl)
{

}

See in the above the list List<Users> is fixed, so I can pass it statically in a method. I'll use the same method to show data in a grid and planning to pass dynamically whenever there are other list of objects. In the above way, I've to declare all the list as below:

public void BindGridView(int pageIndex, List<Groups> lstGroups, GridView grd, Panel pl)
{
}

public void BindGridView(int pageIndex, List<GroupDetails> lstGroupDetails, GridView grd, Panel pl)
{
}

Is ther any way where I can declare it dynamically something like List<Dynamic>, say for utility purpose, so every time I can pass any list of object?

1 Answers

You're most likely looking for generics here. i.e:

public void BindGridView<T>(int pageIndex, List<T> lstUsers, GridView grd, Panel pl)
{
    ...
}
Related