Click here to Skip to main content
15,913,610 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionAssembly Pin
kankeyan5-Jul-07 21:53
kankeyan5-Jul-07 21:53 
AnswerRe: Assembly Pin
originSH5-Jul-07 22:17
originSH5-Jul-07 22:17 
AnswerRe: Assembly Pin
Ilya Verbitskiy8-Jul-07 1:00
Ilya Verbitskiy8-Jul-07 1:00 
QuestionGnerate a pdf file using c# without using a third party product???? Pin
Nithin Krishna5-Jul-07 21:50
Nithin Krishna5-Jul-07 21:50 
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 
I think generally you want to avoid get accessors that have a "side effect" like this. The better way would be to ensure that the variable is set to the appropriate default in the constructor (or when it is declared) and then restrict the allowable values in the set accessor.

For your example, it would look something like this:
C#
private string _name;
 
public string Name
{
    get
    {
        return this._name;
    }
    set 
    {
       // Take your choice here. If you want to prevent nulls and
       // throw an exception use this:
       if (value == null)
       {
          throw new ArgumentNullException("value");
       }
       
       // otherwise, if you just want to prevent nulls you
       // could use this:
       if (value == null)
       {
          value = String.Emtpy;
       }
     
       if (String.Compare(this._name, value, StringComparison.InvariantCultureIgnoreCase) != 0)
       {
          this._name = value; 
       }
    }
}


The call to String.Compare isn't required but it prevents the backing variable from being changed unnecessarily.

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

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 
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 

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.