Possible Duplicate:
What is the “??” operator for?
What does the “??” operator perform in an expression ?
public NameValueCollection Metadata
{
get { return metadata ?? (metadata = new NameValueCollection()); }
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is known as null-coalescing operator and it acts as following, assume
ais a nullable int andbis a normal intis equal to
which is equal to
Therefore
expanded should look like something like this
which is some kind of a one liner singleton pattern, because the getter returns metadata (an initialized NameValueCollection object) every time its requested, expect the very first time which it’s null at that point, so it initializes it and then returns it. This is off topic but note that this approach to singleton pattern is not thread-safe.