Handy extension method for null-coalesing

Today a colleague asked me a question:
“How do you do a null-coalesce operator which will return a property of an object when not null?”
If you’re not familiar with the null coalesce operator it’s the ?? operator and it can be u…


This content originally appeared on Posts on LINQ to Fail and was authored by Posts on LINQ to Fail

Today a colleague asked me a question: “How do you do a null-coalesce operator which will return a property of an object when not null?” If you’re not familiar with the null coalesce operator it’s the ?? operator and it can be used for inline expressions when the test object is null. You use it like so: string test = null; Console.WriteLine(test ?? "The string was null"); So it either returns itself or it returns your value, but what if you want to return a property of the object not itself, well you can’t use the ?


This content originally appeared on Posts on LINQ to Fail and was authored by Posts on LINQ to Fail


Print Share Comment Cite Upload Translate Updates
APA

Posts on LINQ to Fail | Sciencx (2010-04-25T00:00:00+00:00) Handy extension method for null-coalesing. Retrieved from https://www.scien.cx/2010/04/25/handy-extension-method-for-null-coalesing/

MLA
" » Handy extension method for null-coalesing." Posts on LINQ to Fail | Sciencx - Sunday April 25, 2010, https://www.scien.cx/2010/04/25/handy-extension-method-for-null-coalesing/
HARVARD
Posts on LINQ to Fail | Sciencx Sunday April 25, 2010 » Handy extension method for null-coalesing., viewed ,<https://www.scien.cx/2010/04/25/handy-extension-method-for-null-coalesing/>
VANCOUVER
Posts on LINQ to Fail | Sciencx - » Handy extension method for null-coalesing. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2010/04/25/handy-extension-method-for-null-coalesing/
CHICAGO
" » Handy extension method for null-coalesing." Posts on LINQ to Fail | Sciencx - Accessed . https://www.scien.cx/2010/04/25/handy-extension-method-for-null-coalesing/
IEEE
" » Handy extension method for null-coalesing." Posts on LINQ to Fail | Sciencx [Online]. Available: https://www.scien.cx/2010/04/25/handy-extension-method-for-null-coalesing/. [Accessed: ]
rf:citation
» Handy extension method for null-coalesing | Posts on LINQ to Fail | Sciencx | https://www.scien.cx/2010/04/25/handy-extension-method-for-null-coalesing/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.