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

C#

 
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 
There are a number of issues here, when speaking about a generic answer rather than one strictly limited to the examples given, with one potentially important one so far not mentioned: the assignment will happen at different times.

In your first example, SettingValue is assigned after all base constructors have been executed. In your second example, which uses field initialisation, SettingValue is assigned before any base constructors have been executed.

This may affect what exceptions are thrown on construction errors. For instance, a ConfigurationErrorsException will be thrown if the value is not found. In the first example, you can catch this in the constructor and set a default, or give a more detailed exception. In the second example, you can't, and will have to rely on it being caught outside the class.

And if a base constructor would also throw an exception, in your first example this is what will be thrown, while in the second example it's the ConfigurationErrorsException that will be thrown.
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 
QuestionLoading Very Large DataSet Without losing any information Pin
losan16-Apr-13 7:23
losan16-Apr-13 7:23 
AnswerRe: Loading Very Large DataSet Without losing any information Pin
Dave Kreskowiak16-Apr-13 7:58
mveDave Kreskowiak16-Apr-13 7:58 
AnswerRe: Loading Very Large DataSet Without losing any information Pin
SledgeHammer0116-Apr-13 8:05
SledgeHammer0116-Apr-13 8:05 
AnswerRe: Loading Very Large DataSet Without losing any information Pin
Pete O'Hanlon16-Apr-13 9:33
mvePete O'Hanlon16-Apr-13 9:33 
GeneralRe: Loading Very Large DataSet Without losing any information Pin
Rockstar_16-Apr-13 18:24
professionalRockstar_16-Apr-13 18:24 
AnswerRe: Loading Very Large DataSet Without losing any information Pin
Mycroft Holmes16-Apr-13 17:23
professionalMycroft Holmes16-Apr-13 17:23 
AnswerRe: Loading Very Large DataSet Without losing any information Pin
V.16-Apr-13 22:09
professionalV.16-Apr-13 22:09 
AnswerRe: Loading Very Large DataSet Without losing any information Pin
BobJanova17-Apr-13 4:23
BobJanova17-Apr-13 4:23 
AnswerRe: Loading Very Large DataSet Without losing any information Pin
Alan Balkany18-Apr-13 4:55
Alan Balkany18-Apr-13 4:55 
GeneralRe: Loading Very Large DataSet Without losing any information Pin
losan20-Apr-13 7:21
losan20-Apr-13 7:21 
GeneralRe: Loading Very Large DataSet Without losing any information Pin
Alan Balkany22-Apr-13 9:32
Alan Balkany22-Apr-13 9:32 
QuestionCaptured video size is too big Pin
Sanjay K. Gupta16-Apr-13 1:29
professionalSanjay K. Gupta16-Apr-13 1:29 

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.