I am new to Asp .net C#. i have question about objects and inheritance. if i have parent class (Base-Table) that have 2 child classes (Credit-Card-Table , Bank-Account-Table) i have fun. in another class that take an object from the base-table class. my problem is i want to know if the Base-table is Credit-card or Bank-account ?!
class BaseTable
{
string date;
public string Date
{
get { return date; }
set { date = value; }
}
string description;
public string Description
{
get { return description; }
set { description = value; }
}
}
class CreditCardTable:BaseTable
{
string Amount;
public string amount
{
get { return Amount; }
set { Amount = value; }
}
string Type;
public string type
{
get { return Type; }
set { Type = value; }
}
}
class BankAccountTable:BaseTable
{
string Refr;
public string Ref
{
get { return Refr; }
set { Refr = value; }
}
string debit;
public string Debit
{
get { return debit; }
set { debit = value; }
}
string credit;
public string Credit
{
get { return credit; }
set { credit = value; }
}
}
BaseTableshould beabstract? Maybe the other code needs a child instance and not a base instance? What specific reason do you have to need to know the type of the instance?BaseTableis? Usually this means you've gone wrong in your design. The usual way of approaching this would be to make a virtual/abstract method inBaseTablethat is overridden in the derived classes to implement the type-specific behaviour. That way, anything using a BaseTable reference can call the virtual method and get different behaviour depending on the actual type of theBaseTablereference.