Chained null checks and the Maybe monad(devtalk.net)
submitted by
dmitri(408) 1 year, 8 months ago
A great many programmers have met a situation where, while accessing a nested object property (e.g., person.Address.PostCode), they have to do several null checks. This requirement frequently pops up in XML parsing where missing elements and attributes can return null when you attempt to access them (and subsequently trying to access Value throws a NullReferenceException). In this article, I’ll show how a take on the Maybe monad in C#, coupled with use of extension methods, can be used to improve readability.
|category: C#
|Views: 253
tags:
C# another
Everyones tags:
Your Tags: