Click here to Skip to main content
16,012,316 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Gnerate a pdf file using c# without using a third party product???? Pin
Christian Graus5-Jul-07 23:44
protectorChristian Graus5-Jul-07 23:44 
AnswerRe: Gnerate a pdf file using c# without using a third party product???? Pin
Vasudevan Deepak Kumar9-Jul-07 2:57
Vasudevan Deepak Kumar9-Jul-07 2:57 
QuestionGood practice or not? Defaulting member variables via properties Pin
AEternal5-Jul-07 8:00
AEternal5-Jul-07 8:00 
AnswerRe: Good practice or not? Defaulting member variables via properties Pin
Scott Dorman5-Jul-07 8:13
professionalScott Dorman5-Jul-07 8:13 
GeneralRe: Good practice or not? Defaulting member variables via properties Pin
AEternal5-Jul-07 8:27
AEternal5-Jul-07 8:27 
GeneralRe: Good practice or not? Defaulting member variables via properties Pin
Scott Dorman5-Jul-07 8:39
professionalScott Dorman5-Jul-07 8:39 
GeneralRe: Good practice or not? Defaulting member variables via properties Pin
AEternal5-Jul-07 8:47
AEternal5-Jul-07 8:47 
GeneralRe: Good practice or not? Defaulting member variables via properties Pin
Scott Dorman5-Jul-07 9:02
professionalScott Dorman5-Jul-07 9:02 
No problem. I'm glad I was able to clarify the example.

It is very similar functionaly to your original example. The benefit here is that you guarantee that accessing a property does not change the internal state of your object, generally termed a "side effect". In your example, the internal state could possibly change when the property is accessed.

In order to achieve your result of guaranteeing that the property is not null when it is accessed, the backing variable should be set to some appropriate default (in this case, String.Emtpy) as early as possible and then the property should prevent someone from explicitly setting it to null.

The choice is yours to decide how to restrict setting it to null and depends on your desired behavior. I have written properties using both methods and they both have their place, you just need to decide which is appropriate for your context.

A lot of properties (particularly in the CLR itself) raise property change events when the value of the property changes. These events are not "smart" so they are always raised. The call to the String.Compare method prevents the property from being set to the same value it currently holds, which prevents the property change events from being raised.


-----------------------------
In just two days, tomorrow will be yesterday.

GeneralRe: Good practice or not? Defaulting member variables via properties Pin
AEternal5-Jul-07 9:42
AEternal5-Jul-07 9:42 
GeneralRe: Good practice or not? Defaulting member variables via properties Pin
Scott Dorman5-Jul-07 9:49
professionalScott Dorman5-Jul-07 9:49 
GeneralRe: Good practice or not? Defaulting member variables via properties Pin
Not Active5-Jul-07 9:58
mentorNot Active5-Jul-07 9:58 
QuestionUnRegistering Assemblies from GAC on the basis of public key? Pin
Mushtaque Nizamani5-Jul-07 4:18
Mushtaque Nizamani5-Jul-07 4:18 
AnswerRe: UnRegistering Assemblies from GAC on the basis of public key? Pin
Ilya Verbitskiy8-Jul-07 1:07
Ilya Verbitskiy8-Jul-07 1:07 
QuestionProblem with .net Pin
koolprasad20034-Jul-07 19:21
professionalkoolprasad20034-Jul-07 19:21 
AnswerRe: Problem with .net Pin
Sathesh Sakthivel5-Jul-07 16:38
Sathesh Sakthivel5-Jul-07 16:38 
GeneralRe: Problem with .net Pin
Paul Conrad6-Jul-07 15:33
professionalPaul Conrad6-Jul-07 15:33 
GeneralRe: Problem with .net Pin
Sathesh Sakthivel6-Jul-07 15:48
Sathesh Sakthivel6-Jul-07 15:48 
GeneralRe: Problem with .net Pin
Paul Conrad6-Jul-07 17:24
professionalPaul Conrad6-Jul-07 17:24 
Questionneed help wit code snippet Pin
neodeaths4-Jul-07 16:29
neodeaths4-Jul-07 16:29 
AnswerRe: need help wit code snippet Pin
Christian Graus4-Jul-07 17:12
protectorChristian Graus4-Jul-07 17:12 
QuestionReference to running application. Pin
Ylno4-Jul-07 6:39
Ylno4-Jul-07 6:39 
AnswerRe: Reference to running application. Pin
SHatchard5-Jul-07 0:27
SHatchard5-Jul-07 0:27 
QuestionSteps for???? Pin
PACO774-Jul-07 5:05
PACO774-Jul-07 5:05 
AnswerRe: Steps for???? Pin
originSH4-Jul-07 22:44
originSH4-Jul-07 22:44 
GeneralRe: Steps for???? Pin
PACO774-Jul-07 23:16
PACO774-Jul-07 23:16 

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.