TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
aa
NA
10
0
Need Help with Properties in C#
Jan 26 2007 11:09 PM
Hi 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 [B]what I had before[/B]
4 classes
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.
[code] // this is in the bankAccount class public string FirstName { get { return this.firstName; } } [/code]
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
[code] example 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); } [/code] But of course this does not work so how do I do it now?
Thanks
Reply
Answers (
1
)
Change tabPage tab from another form
sfewfsdfsd