Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abstract type as parameter in method (.net, c#)

Tags:

c#

.net

generics

I have the following method which I use to fill a DropDownList-Control.

protected void LoadDropDownList(DropDownList ddl, IEnumerable<A> source)
{
    ddl.DataSource = source;
    ddl.DataBind();
}

My question is, can I make the method more abstract so that it can also take IEnumerables of type B?

like image 808
AGuyCalledGerald Avatar asked Dec 21 '22 09:12

AGuyCalledGerald


1 Answers

protected void LoadDropDownList<T>(DropDownList ddl, IEnumerable<T> source) { 
    ...

See also.

like image 196
i_am_jorf Avatar answered Dec 24 '22 02:12

i_am_jorf