| | |
C# Classes
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
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 2007 access algorithm array barchart bitmap box broadcast c# camera check checkbox client combobox control conversion cs4 csharp custom customactions database datagrid datagridview dataset date datetime degrees development draganddrop drawing encryption enum event eventcloseformc# excel file form format forms function gdi+ handler httpwebrequest image index input install java keypress label list listbox listener listview load mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting resolved. richtextbox search security server sleep socket sql statistics stream string table text textbox thread time timer update usercontrol validation view visual visualstudio webbrowser windows winforms wordautomation wpf xml





