开发者

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

开发者 https://www.devze.com 2023-04-01 01:31 出处:网络
I have the following method which I use to fill a DropDownList-Control. protected void LoadDropDownList(DropDownList ddl, IEnumerable<A> source)

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();
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号