Today I found myself fighting with Visual Studio about how to check if the result of a FirstOrDefault operation on a list of a value type was null. Tried all the following and nothing worked, even with several results from stack overflow.
After a bit of google I noticed that I was not the only one with this kind of problem as it seems that the new value tuples don't play well with enumerable just yet. So I went back to use reference types for this case as the solution I found is far from elegant and error prone:
I created a quick test harness to try to find a "solution" to my problem:
My first reflex was to check if it was null as we usually do with generic lists of non value types.
My first reflex was to check if it was null as we usually do with generic lists of non value types.
Then I realized that I was so used to work with enumerables of reference types that I had completely overlooked the name of this new types value tuple, so I tried to check for defaults.So I tried with default, default of value type and default of tuple, none of them work.
For this last one I also switched from C# 7 to 7.1, but the compiler continued complaining.
No comments:
Post a Comment