I kind of understand what an interface does -but I am not too sure why I would use a built in Interface (ie. IClonable, IFormattable, IEnummerable) are they like some kind of template or is there something fundamental about them?
Below is kind of a second question....
I came across this site...
http://articles.directorym.net/_NET_Tip_Take_Advantage_of_Interfaces-a923831.html ...and it mentioned to take advantage of Interfaces.
In the extract below the "ICollection" is playing a big part -but I'm not sure what?
<extract >
private void LoadListBox(object[] data, ListBox ListBoxControl)
{ for (int i = 0; i < data.Length; i++) ListBoxControl.Items.Add(d
ata[i].ToS
tring()); }
With the LoadListBox method in place, the code to populate the ListBox in the Page_Load method is simplified. string[] TestItems = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; LoadListBox(TestItems, ListBox1);
Although this is better than doing all the work in the Page_Load method, you can do much better. This works fine for a ListBox, but what about other list type controls? If you apply interfaces, you can enhance the helper method to support a variety of data sources and list type controls. Instead of the helper method taking an array of data items and a ListBox control, it now takes an ICollection and a ListControl.
private void LoadListControlFromCollect
ion(IColle
ction data, ListControl ListControlControl)
{ foreach (object item in data) ListControlControl.Items.A
dd(item.To
String());
}
Usage of the new LoadListControlFromCollect
ion method to load a ListBox with data items remains the same. string[] TestItems = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; LoadListControlFromCollect
ion(TestIt
ems, ListBox1);
</extract>
many thanks for help in advance
Start Free Trial