C
chambersdon
I need to create an abstract class but have the method in the derived
class differ by the return type.
This is my code:
//Abstract class
public abstract class DataItem
{
public abstract DbDataReader getRecord();
}
//Derived Class
public class DistributionCode
ataItem
{
public override SQLDataReader getRecord()
{
SqlDataReader r = getReader();
return r;
}
My problem is the return type, SQLDataReader in the derived class.
This causes a compiler error that states ‘the return type must be
DbDataReader’.
Microsoft seems to be doing this ExecuteReader method of the
SqlCommand class.
The SQLCommand class inherits from DBCommand (abstract class).
The DBCommand class has a method called ExecuteReader that returns a
DbDataReader.
The the overridden ExecuteReader method, in SQLCommand returns a
SQLDataReader, not the DbDataReader from its base class.
class differ by the return type.
This is my code:
//Abstract class
public abstract class DataItem
{
public abstract DbDataReader getRecord();
}
//Derived Class
public class DistributionCode

{
public override SQLDataReader getRecord()
{
SqlDataReader r = getReader();
return r;
}
My problem is the return type, SQLDataReader in the derived class.
This causes a compiler error that states ‘the return type must be
DbDataReader’.
Microsoft seems to be doing this ExecuteReader method of the
SqlCommand class.
The SQLCommand class inherits from DBCommand (abstract class).
The DBCommand class has a method called ExecuteReader that returns a
DbDataReader.
The the overridden ExecuteReader method, in SQLCommand returns a
SQLDataReader, not the DbDataReader from its base class.