Is it possible to change a base class field data type and value in the derived class and still call the base class method but use the derived class values?
Sample Code:
public class class1
{
protected DBContext DB { get; set; }
public A()
{
DB = new DBContext();
}
public virtual DBRecord find(int id)
{
return DB.DBRecord.Find(id);
}
}
public class class2 : class2
{
protected DifferentDBContext DB { get; set; }
public B()
{
DB = new DifferentDBContext();
}
}
And then i tried to call the method with the code below.
class2 x = new class2();
x.find(1); // calls the base class method with base class field values
Basing on what's happening, it's calling the base class method with the base class variables. I want to know if it's possible to set the field type/value in derived class and then call the base class method? because they just have the same implementation but just using different values.
What I've done so far (which i feel is so redundant) and working.
public class class2 : class1
{
//Other implementations omitted
public override DBRecord find(int id)
{
return DB.DBRecord.Find(id);
}
}
Note: this may be just a simple OOP principle but you know, people get confused with that sometimes, just like me :-)