Skip to content

Instantly share code, notes, and snippets.

@cerkit
Last active March 28, 2016 22:17
Show Gist options
  • Save cerkit/15e6ef7f4f877795b633 to your computer and use it in GitHub Desktop.
Save cerkit/15e6ef7f4f877795b633 to your computer and use it in GitHub Desktop.
I have a dilemma. Should I use line 4, 8, 12, or 16?
// Dilemma, should I use this code:
// NOTE: existingJobDetail.Id is defined as a regular (non-nullable) int.
int? parentJobDetailId = existingJobDetail != null ? existingJobDetail.Id as int? : null;
// Or this code:
int? parentJobDetailId = existingJobDetail != null ? (int?)existingJobDetail.Id : null;
// Or (less likely):
int? parentJobDetailId = existingJobDetail != null ? existingJobDetail.Id as Nullable<int>: null;
// Or:
int? parentJobDetailId = existingJobDetail != null ? (Nullable<int>)existingJobDetail.Id : null;
@PaulLockwood
Copy link

Can you not just create a new nullable variable do a SetValue? I don't have a C# compiler handy + have done very little C# for quite a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment