method type ICollection returns Dataview

J

Janus Knudsen

Hello :O)

Im in the process of learning asp.net, and i'm reading a nice book. But then
suddenly i came across this:

public ICollection DataLoad()

{

DataTable dtEmployee = new DataTable();

DataRow drEmployee;


dtEmployee.Columns.Add(new DataColumn("emp_id",
System.Type.GetType("System.Int16")));

dtEmployee.Columns.Add(new DataColumn("emp_name",
System.Type.GetType("System.String")));



drEmployee = dtEmployee.NewRow();

drEmployee["emp_id"] = 1;

drEmployee["emp_name"] = "E.E. Smith";

dtEmployee.Rows.Add(drEmployee);


dvEmployee = new DataView(dtEmployee);

return dvEmployee;

}



The method type is ICollection but it returns a DataView - what's the
purpose of that? The caller then casts it as a DataView in order to use it,
is't a normal approach or? And what about overhead with all that
typecasting?



Kind regards
 
N

Natty Gur

Hi,

Since DataView implement ICollection therefore the function can return
DataView. the idea behind such code is flexibility. Every function can
call that method, expect ICollection as result and work against
ICollection defined methods and properties. This way of programming
enables DataLoad users to work with that function even if you change
function implementation, because programmers works against Interface


Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top