Click here to Skip to main content
16,004,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sending packet to a specified IP address & predefined the contents of it... Pin
3bood.ghzawi5-Dec-09 2:51
3bood.ghzawi5-Dec-09 2:51 
QuestionA Question About Class Properties Pin
Roger Wright4-Dec-09 17:15
professionalRoger Wright4-Dec-09 17:15 
AnswerRe: A Question About Class Properties Pin
PIEBALDconsult4-Dec-09 17:44
mvePIEBALDconsult4-Dec-09 17:44 
GeneralRe: A Question About Class Properties Pin
Roger Wright4-Dec-09 18:02
professionalRoger Wright4-Dec-09 18:02 
GeneralRe: A Question About Class Properties Pin
DaveyM694-Dec-09 21:06
professionalDaveyM694-Dec-09 21:06 
GeneralRe: A Question About Class Properties Pin
Roger Wright5-Dec-09 2:59
professionalRoger Wright5-Dec-09 2:59 
GeneralRe: A Question About Class Properties Pin
PIEBALDconsult5-Dec-09 4:17
mvePIEBALDconsult5-Dec-09 4:17 
AnswerRe: A Question About Class Properties Pin
Richard Blythe4-Dec-09 18:08
Richard Blythe4-Dec-09 18:08 
Roger Wright wrote:
...created all the form data members as private


Are you refering to controls? Textbox, Combobox, etc.

It is important for these to private by default, because it would open up a hugh security hole.

As far as the value of a property itself, it can be very useful when you are wanting to validate the input. Say for instance you had a class named Car. The max speed that the car could go was 120 mph.
Using "set", you could make sure that no speed was set above the maximum allowable speed.

public class Car
{
private const byte MAX_SPEED = 120;

public byte Speed
{
get { return _Speed; }
set
{
if (value > MAX_SPEED)
throw new ArgumentException("Speed cannot exceed: " + MAX_SPEED.ToString());
else
_Speed = value
}
}

}

Does this help? By the way a property is compiled into two methods. get_Speed() and set_Speed(). Properties are just C# short hand for these two methods.

Cheers!
Richard

If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

GeneralRe: A Question About Class Properties Pin
Roger Wright4-Dec-09 18:24
professionalRoger Wright4-Dec-09 18:24 
GeneralRe: A Question About Class Properties Pin
Richard Blythe4-Dec-09 18:39
Richard Blythe4-Dec-09 18:39 
GeneralRe: A Question About Class Properties Pin
Roger Wright4-Dec-09 18:58
professionalRoger Wright4-Dec-09 18:58 
AnswerRe: A Question About Class Properties Pin
Luc Pattyn5-Dec-09 3:06
sitebuilderLuc Pattyn5-Dec-09 3:06 
QuestionReading x64 registry keys from a x86 computer remotely Pin
Jacob Dixon4-Dec-09 14:53
Jacob Dixon4-Dec-09 14:53 
AnswerRe: Reading x64 registry keys from a x86 computer remotely Pin
Dave Kreskowiak4-Dec-09 17:05
mveDave Kreskowiak4-Dec-09 17:05 
GeneralRe: Reading x64 registry keys from a x86 computer remotely Pin
Jacob Dixon4-Dec-09 18:13
Jacob Dixon4-Dec-09 18:13 
GeneralRe: Reading x64 registry keys from a x86 computer remotely Pin
Dave Kreskowiak5-Dec-09 3:41
mveDave Kreskowiak5-Dec-09 3:41 
GeneralRe: Reading x64 registry keys from a x86 computer remotely Pin
Jacob Dixon5-Dec-09 4:04
Jacob Dixon5-Dec-09 4:04 
QuestionActivating a child form Pin
electriac4-Dec-09 13:20
electriac4-Dec-09 13:20 
AnswerRe: Activating a child form Pin
Luc Pattyn4-Dec-09 13:27
sitebuilderLuc Pattyn4-Dec-09 13:27 
GeneralRe: Activating a child form Pin
electriac4-Dec-09 15:06
electriac4-Dec-09 15:06 
GeneralRe: Activating a child form Pin
Luc Pattyn4-Dec-09 15:45
sitebuilderLuc Pattyn4-Dec-09 15:45 
GeneralRe: Activating a child form Pin
electriac5-Dec-09 0:11
electriac5-Dec-09 0:11 
AnswerRe: Activating a child form Pin
Roger Wright4-Dec-09 17:29
professionalRoger Wright4-Dec-09 17:29 
AnswerRe: Activating a child form Pin
Shameel4-Dec-09 23:08
professionalShameel4-Dec-09 23:08 
GeneralRe: Activating a child form Pin
electriac5-Dec-09 0:07
electriac5-Dec-09 0:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.