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

I have the following method that I use to populate 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 accept IEnumerables of type B?

+4
source share
2 answers
 protected void LoadDropDownList<T>(DropDownList ddl, IEnumerable<T> source) { ... 

See also .

+8
source
 protected void LoadDropDownList(DropDownList ddl, IEnumerable source) { ddl.DataSource = source; ddl.DataBind(); } 
+3
source

Source: https://habr.com/ru/post/1369510/


All Articles