简体   繁体   中英

Dynamically Pass List of Object As A Parameter

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?

You're most likely looking for generics here. ie:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM