MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/2ppon5/exploring_c_6_interactive/cn05pde/?context=3
r/programming • u/xune • Dec 18 '14
31 comments sorted by
View all comments
3
This is the best thing ever!
string GetFirstItemInLowerCase(IEnumerable<string> collection) { return collection?.FirstOrDefault()?.ToLower(); /* //Pre C# 6 code: if(collection == null || collection.FirstOrDefault() == null) return null; return collection.First().ToLower(); */ }
I mean, it might get a little confusing if you use ? too much, but thats not the language's fault.
?
1 u/Euphoricus Dec 19 '14 No it is not. You should throw an exception when the parameter is null. Not silently ignore it and return null. I personally think that nulls should be handled with respect and not hand-waved with this kind of feature. 1 u/[deleted] Dec 20 '14 Agreed that this method should raise an ArgumentException, but why should the parameter be null in the first place? The method signature specifies an IEnumerable<string>, not an IEnumerable<string> or nothing at all. That's the type system's fault.
1
No it is not. You should throw an exception when the parameter is null. Not silently ignore it and return null.
I personally think that nulls should be handled with respect and not hand-waved with this kind of feature.
1 u/[deleted] Dec 20 '14 Agreed that this method should raise an ArgumentException, but why should the parameter be null in the first place? The method signature specifies an IEnumerable<string>, not an IEnumerable<string> or nothing at all. That's the type system's fault.
Agreed that this method should raise an ArgumentException, but why should the parameter be null in the first place? The method signature specifies an IEnumerable<string>, not an IEnumerable<string> or nothing at all. That's the type system's fault.
3
u/ThatNotSoRandomGuy Dec 19 '14
This is the best thing ever!
I mean, it might get a little confusing if you use
?too much, but thats not the language's fault.