Tag: CSharp7

Using Tuples for Overriding Equality and GetHashCode

Overriding Objects 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 […]

Generalized Async Return Types in C# 7.0

Instantiating a Task in C# 7.0 Ever since C# 5.0 when the async/await pattern was introduced, the only supported return types were Task, 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 […]

C# 7 Deconstructors: Implement an Implicit Conversion

Deconstructors in C# 7 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, […]