Here i have my deposit class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace CollectionAccounts
{
public class DepositAccount : Account,IDisplayable
{
private double interestRate;
public DepositAccount(string id)
: base(id)
{
interestRate = 0;
}
public double InterestRate
{
get;private set;
}
public void AddInterest()
{
balance *= 1 + interestRate / 100;
}
public override void Withdraw(double amount)
{
if (amount <= (balance))
{
balance -= amount;
}
else
Console.WriteLine("Not allowed as amount exeeds balance\n");
}
public void Display()
{
Console.WriteLine("The id is {0} and balance is {1}", id, balance);
}
}
}
...............................................................................................
The problem resides in the last line here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CollectionAccounts
{
class Program
{
static void Main(string[] args)
{
Account[] obj = new Account[2];
obj[0] = new CurrentAccount("ca001");
obj[1] = new DepositAccount("da001");
obj[0].Lodge(200);
((CurrentAccount)obj[0]).Creditlimit = 500;
obj[0].Withdraw(500);
((CurrentAccount)obj[0]).Display();
obj[1].Lodge(200);
((DepositAccount)obj[1]).interestRate = 2.5; ?????Does not work
}
}
}
I tried ((DepositAccount)obj[1]).AddInterest = 2.5;
Does not work too. Please help.