c# - What is the difference between 0d and (double)0? -
example 1:
if ((value ?? 0d) <= 0d) { //some code } example 2:
if ((value ?? (double)0) <= (double)0) { //some code } what difference between these two? , 1 improve use?
both code snippets equivalent, type-cast performed compiler @ compile-time, , result treated constant. note standard behaviour, not compiler optimization; otherwise, not able utilize casts constants:
const double d1 = (double)0; // allowed const double d2 = math.pow(2, 4); // error: "the look beingness assigned 'd2' must constant" specifying proper literal suffix nonetheless preferred keeps code concise. popular convention specifying doubles append .0:
if ((value ?? 0.0) <= 0.0) c#
No comments:
Post a Comment