DEV Community

Discussion on: No more NullReferenceException for Lists in C#

Collapse
 
gfoley83 profile image
Gavin Foley

Under what scenarios would you want a null list?

Collapse
 
josemedina760 profile image
Jose Medina

Exactly...

Collapse
 
Sloan, the sloth mascot
Comment deleted
 
gfoley83 profile image
Gavin Foley

I agree with what you're saying for objects but not for collections. I see no value in having null collections.

Thread Thread
 
Sloan, the sloth mascot
Comment deleted
 
gfoley83 profile image
Gavin Foley • Edited

But collections aren't just objects. They serve a different purpose.
I'm familiar with the builder pattern and I see no need to use nullable lists with it:

gist.github.com/GFoley83/878c2ac59...

Note the parts dictionary and why initializing it saves having to null check everywhere in derived classes.

Best practice with arrays has always been to initialize arrays in any language I've used.

Thread Thread
 
Sloan, the sloth mascot
Comment deleted
 
gfoley83 profile image
Gavin Foley • Edited

Hmmm, no I get the point just fine you're just wrong and too obnoxious to admit it.

You're quoting the builder pattern like it somehow proves your point when it doesn't, nor have you provided anything to support your criticism of the article above. I don't like the extension method personally but your comment promotes bad practice so I thought it would be a good idea to comment.

I can find more articles than can be counted showing why you should initialize arrays in any language.

Builder ex. note how and why the dictionary is initialized

gist.github.com/GFoley83/878c2ac59...