0
votes
1answer
424 views

Should we always write Defensive null check in code? [duplicate]

Are there any scenarios where we should not write defensive checks for null? Should we write defensive code or check for NULL every time we have passed a parameter or received a value back from a ...
5
votes
2answers
281 views

Requiring Explicit Null Reference Handling

One of the problems I have with null references is that they may not be exceptional. In my current position, there are few requirements and you are lucky if conventions are followed. This means being ...
7
votes
8answers
805 views

AND is better or using Internal “IF”

In a situation like this:" if ((metadata != null) && (metadata.TypeEnum != VariantInfoMetadata.CellTypeEnum.Status)) do you recommend to keep the code as it is above? Or is it better to ...
9
votes
7answers
3k views

How does throwing an ArgumentNullException help?

Let's say I have a method: public void DoSomething(ISomeInterface someObject) { if(someObject == null) throw new ArgumentNullException("someObject"); someObject.DoThisOrThat(); } I've been ...
7
votes
10answers
1k views

Property-coalescing operator for C#

The null-coalescing operator in c# allows you to shorten the code if (_mywidget == null) return new Widget(); else return _mywidget; Down to: return _mywidget ?? new Widget(); I ...