when to use nullable short hand and what is the peformance impact, if any? [duplicate]

StackOverflow https://stackoverflow.com/questions/19710333

  •  02-07-2022
  •  | 
  •  

سؤال

the null-able short hand property

public long? id{get;set}

what is the incentive of using it, other than if you are reading it from a database, is there a chance the value might be null...?

also, if you want to get the id,

 int a = id.value;

what is the performance impact on this? and in which situation will you be compelled to use this shorthand. Please share your thoughts on this

هل كانت مفيدة؟

المحلول

The advantage is the direct check if is null or no

long v = id ?? v2; //if id is null v will get the v2 value

And the performance is pratically the same of a normal one

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top