Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
GeneralRe: The SetAttribute does not set attribute Pin
Meysam Toluie18-Apr-13 1:30
Meysam Toluie18-Apr-13 1:30 
GeneralRe: The SetAttribute does not set attribute Pin
Jasmine250118-Apr-13 6:04
Jasmine250118-Apr-13 6:04 
GeneralRe: The SetAttribute does not set attribute Pin
Meysam Toluie20-Apr-13 3:02
Meysam Toluie20-Apr-13 3:02 
GeneralRe: The SetAttribute does not set attribute Pin
Jasmine250122-Apr-13 5:24
Jasmine250122-Apr-13 5:24 
AnswerRe: The SetAttribute does not set attribute Pin
OriginalGriff17-Apr-13 8:41
mveOriginalGriff17-Apr-13 8:41 
GeneralRe: The SetAttribute does not set attribute Pin
Meysam Toluie17-Apr-13 19:35
Meysam Toluie17-Apr-13 19:35 
GeneralRe: The SetAttribute does not set attribute Pin
dusty_dex17-Apr-13 23:46
dusty_dex17-Apr-13 23:46 
QuestionWhich Constructor is Better? Pin
Jasmine250116-Apr-13 12:15
Jasmine250116-Apr-13 12:15 
This is kind of for my own entertainment, but I was about to say "the second thing is better" to someone, but now that I think about it I'm not sure...

Option 1
C#
public class MyClass {
  private System.String SettingValue = ""; 
  private System.String SETTING_KEY = "SomeSettingKey"; 


  public MyClass() {
  	this.Server = System.Configuration.ConfigurationManager.AppSettings[this.SETTING_KEY];
  }
}


Option 2
C#
public class MyClass {
    private System.String SettingValue = 
        System.Configuration.ConfigurationManager.AppSettings["SomeSettingKey"];


    public MyClass() { }
}


My reasoning is that the setting key is only ever used in one place so creating a constant is unnecessary overhead, and secondly, there is no reason to create an empty string, then discard that string to the garbage heap, then set it to the value you really wanted... just set it to the correct value on instantiation.
AnswerRe: Which Constructor is Better? Pin
Matt T Heffron16-Apr-13 12:47
professionalMatt T Heffron16-Apr-13 12:47 
GeneralRe: Which Constructor is Better? Pin
Jasmine250116-Apr-13 14:34
Jasmine250116-Apr-13 14:34 
GeneralRe: Which Constructor is Better? Pin
PIEBALDconsult16-Apr-13 15:01
mvePIEBALDconsult16-Apr-13 15:01 
GeneralRe: Which Constructor is Better? Pin
Jasmine250117-Apr-13 5:36
Jasmine250117-Apr-13 5:36 
GeneralRe: Which Constructor is Better? Pin
Matt T Heffron17-Apr-13 9:53
professionalMatt T Heffron17-Apr-13 9:53 
GeneralRe: Which Constructor is Better? Pin
Jasmine250117-Apr-13 9:57
Jasmine250117-Apr-13 9:57 
GeneralRe: Which Constructor is Better? Pin
Matt T Heffron17-Apr-13 10:02
professionalMatt T Heffron17-Apr-13 10:02 
GeneralRe: Which Constructor is Better? Pin
Jasmine250117-Apr-13 10:04
Jasmine250117-Apr-13 10:04 
AnswerRe: Which Constructor is Better? Pin
Matt T Heffron17-Apr-13 10:07
professionalMatt T Heffron17-Apr-13 10:07 
GeneralRe: Which Constructor is Better? Pin
Matt T Heffron17-Apr-13 13:35
professionalMatt T Heffron17-Apr-13 13:35 
AnswerRe: Which Constructor is Better? Pin
V.16-Apr-13 20:23
professionalV.16-Apr-13 20:23 
AnswerRe: Which Constructor is Better? Pin
Orjan Westin16-Apr-13 22:45
professionalOrjan Westin16-Apr-13 22:45 
GeneralRe: Which Constructor is Better? Pin
Richard Deeming17-Apr-13 0:39
mveRichard Deeming17-Apr-13 0:39 
GeneralRe: Which Constructor is Better? Pin
Orjan Westin17-Apr-13 1:58
professionalOrjan Westin17-Apr-13 1:58 
GeneralRe: Which Constructor is Better? Pin
Jasmine250117-Apr-13 5:39
Jasmine250117-Apr-13 5:39 
AnswerRe: Which Constructor is Better? Pin
jschell17-Apr-13 9:18
jschell17-Apr-13 9:18 
GeneralRe: Which Constructor is Better? Pin
Jasmine250117-Apr-13 9:28
Jasmine250117-Apr-13 9:28 

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.