Abstract type as parameter in method (.net, c#)
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 tak开发者_运维问答e IEnumerables of type B?
protected void LoadDropDownList<T>(DropDownList ddl, IEnumerable<T> source) {
...
See also.
protected void LoadDropDownList(DropDownList ddl, IEnumerable source) {
ddl.DataSource = source;
ddl.DataBind();
}
精彩评论