4 ms·
Or embrace them by using the null object pattern. var listofNullandNotNullObjects = getSomeThings(); foreach(var oneThing in listofNullandNotNullObjects) {
by chooseaname 8y ago
Or embrace them by using the null object pattern.
var listofNullandNotNullObjects = getSomeThings();
foreach(var oneThing in listofNullandNotNullObjects) {
oneThing.doSomething(); // null objects would just return
}
- bradenb 8y agoI wish your comment was closer to the top. I totally agree that if you're avoiding nulls this is the right way to do it. I wouldn't say it's right for everything, but when done correctly it makes for some really clean code.