Tag: CSharp7

Using Tuples for overriding Equality() and GetHashCode()

The implementation of Equals() and GetHashCode() used to be complex, but with C# 7.0 Tuples, the actual code is boilerplate. For Equals(): It’s necessary to compare all the contained identifying data structures while avoiding infinite recursion or null reference exceptions. For GetHashCode(): It’s necessary to combine the unique hash code of each of the non-null […]

Generalized Async Return Types in C# 7.0

Ever since C# 5.0 when the async/await pattern was introduced, the only supported return types were Task<TResult>, Task, and void (the latter only in exceptional cases). The problem with this limitation is that on occasions when the result is known immediately, it is still necessary to proceed with the formality of instantiating a Task even though […]

Implementing an Implicit Conversion With C# 7.0 Deconstructors

While the deconstruct syntax is interesting for its convenience in assigning to a set of variables, what I believe has far broader implications is its potential to provide an “implicit conversion operator” and in a syntax that, quite frankly, is far easier to recall than the implicit cast operator.  For example, I can provide deconstructors […]