Need Help with Properties in C#
I been doing my assignment and thought I was finished but I found out when my teacher keep going a read-only string property ( I thought property was C# name for variable - we never talked about it in lec and was not in my notes)
So anyways I got to make changes to my program this is what I had before
BankAccount - base class. This class has some variable and methods.
SavingAccount - inherits stuff from BankAccount but has a couple formating methods and an addinterest method
CheckingAccount - inherits stuff from BankAccount has a couple formating methods and also overrides a withdraw method.
In my bankAccount class I have these variables
protected readonly string firstName;
protected readonly string lastName;
protected readonly string accountNo;
protected readonly string id;
protected decimal balance;
So now all these are suppost to be properties so the first 4 are only readonly
and I am guessing the balance should be read and write(he had only readonly what i don't think can be done otherwise you can't change the balance).
So my question is that my checkingAccount/SavingAccount needs to use these variables and of course now that they are properites they have to be private so now I need to use the properties everytime I need to get these.
So in my inherited classes do I have to go BankAccount acct1 = new BankAccount?
or is there some other way I can do it.
Here is an example what my property looks like.
// this is in the bankAccount class
public string FirstName
but say in my checking class I will have something like a toString method to help format the output the way I want it too look like
public string toString()
// this is how I would do it the old way when I had protected and it was inherited.
return("firstName" + this.firstName);
But of course this does not work so how do I do it now?
Re: Need Help with Properties in C#
|All times are GMT +5.5. The time now is 21:06.|