Re: confusion on interface IDataReader
Shawn Wildermuth <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
As an adjuct (hopefully not to confuse the issue), you can certainly define
a method (or property) in .NET that returns an interface:
IDataReader GetDataReader()
{
// ...
}
You can't return an instance of an IDataReader, but have to return a
reference to an object that supports IDataReader:
IDataReader GetDataReader()
{
// ...
SqlDataReader rdr = cmd.ExecuteReader();
// An implicit cast from SqlDataReader to IDataReader is done here
return rdr;
// You could also (to make the code a little more readable:
// return (IDataReader) rdr;
// - or -
// return rdr as IDataReader;
}
That's perfectly valid, but I understand your confusion...
Thanks,
Shawn Wildermuth
http://adoguy.com
C# MVP, MCSD.NET, Author and Speaker
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com