Hello everybody.
So I have an abstract class named "Account" :
public abstract class Account
{
private string _FinancialInstitution;
public string FinancialInstitution
{
get { return _FinancialInstitution; }
...
}
}
And I have two other classes that extends from those two:
public class CreditCard : Account
{
private DateTime _ExpirationDate;
...
}
and this one:
public class CheckingSavingsAccount : Account
{
private string _PrimaryAccountHolder;
...
}
Now, The whole point was to be able to store either kind of account in a generics collection list, but if I try to do this:
List<Account> lstTemp = new List<Account>();
CreditCard newCC1 = new CreditCard();
lstTemp.Add(new CreditCard());
I got an "Object reference not set to an instance of an object." error on the line that attemps to add the newly credit card object created (lstTemp.Add). What am I doing wrong?
This is the exception detail:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="mscorlib"
StackTrace:
at System.Collections.Generic.List`1.Add(T item)
at RunAsConsole.Program.Main(String[] args) in C:\Users\ortegae\Documents\Visual Studio 2008\Projects\eStocks50600\RunAsConsole\Program.cs:line 52
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: