I\'ve seen some samples of using \'T\' to make a method reuseable for generic collections of different classes, but I\'ve never really gotten into it or understood the samples.
The old school way would be to create a common interface for both Department and Function:
interface A
{
int ID{get;}
string Description{get;}
}
You implement Description on Department to return d.Code + " - " + d.Description
.
and write the function to use this interface instead of concrete classes:
[NonAction]
public List ToSelectList(IEnumerable as, string defaultOption)
{
var items = as.Select(a => new SelectListItem() { Text = a.Description, Value = a.Id.ToString() }).ToList();
items.Insert(0, new SelectListItem() { Text = defaultOption, Value = "-1" });
return items;
}
EDIT: Regarding using generics, its not going to help much in this case, because