| | |
C# Classes
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
can't have spaces so phone number needs to be changed to phoneNumber
also, you probably want to use DateTime instead of int for the birthday. Good luck and keep at it
also, you probably want to use DateTime instead of int for the birthday. Good luck and keep at it
C# Syntax (Toggle Plain Text)
private string name; private string phoneNumber; private DateTime birthday;
•
•
Join Date: Jan 2006
Posts: 275
Reputation:
Solved Threads: 11
maybe consider using a property for each of these. It would appear that you will want something outside of your class to change the values so you dont want to make your fields public (or internal) as you have no control over the values in there.
To create a property you need a private field and a property for each as follows:
You have full control when someone changes the value now.
I use them alot as private properties for just in time instantiation (the field is populated the first time the property is used so it isnt taking up memory.
Also you can make it read only by not using the set part of the property (leave it out altogether)
You can also have different accessors so the get part can be public and the set part can be private or internal.
Hope it helps you
To create a property you need a private field and a property for each as follows:
C# Syntax (Toggle Plain Text)
private string _name; public string name { get { return _name; } set { //do some validation if you want _name = value; //do some other stuff if you need to based on the new value } }
I use them alot as private properties for just in time instantiation (the field is populated the first time the property is used so it isnt taking up memory.
Also you can make it read only by not using the set part of the property (leave it out altogether)
You can also have different accessors so the get part can be public and the set part can be private or internal.
Hope it helps you
![]() |
Similar Threads
- need idea for project using classes and inheritance (C++)
- How do i do chat program using MFC (Microsoft Foundation Classes) and Visual Basic? (Visual Basic 4 / 5 / 6)
- Loading classes from a .jar file (Java)
- Help with Classes (C++)
- Understanding classes (C++)
- Working with objects of different Classes (Java)
- Classes (C++)
- Summer Classes (Geeks' Lounge)
Other Threads in the C# Forum
- Previous Thread: C# VS2005 - Installing deployed application to an specif path
- Next Thread: Opening a notepad file
| Thread Tools | Search this Thread |
.net access algorithm array asp.net bitmap box broadcast c# check checkbox client combobox control conversion csharp database datagrid datagridview dataset datetime dbconnection decryption degrees design developer draganddrop drawing encryption enum eventhandlers excel file firefox focus form format forms function gdi+ grantorrevokepermissionthroughc#.net hospitalmanagementsystem image input install interface java libraries list loop marshalbyrefobject math mouseclick movingimage mysql netcfsvcutil.exe numeric operator path photoshop php picturebox pixelinversion platform polynomial post programming properties radians read regex remote remoting richtextbox server sleep socket sql statistics string stringformatting study system.servicemodel table tcpclientchannel text textbox thread time timer update usb usercontrol validation visualstudio webbrowser winforms wpf wpfc# xml





