C# 7.3 Features : Tuple Comparison & Generic Constraints

C# 7.3 is another minor roll-out that brings along with ‘seemingly minor’ improvement, but ones that definitely opens new opportunities. In this blog post, we will explore¬† two features that are introduced in 7.3

Tuple Comparison

C# 7.x had already made tuple an immensely powerful tool with a variety of features, and the latest minor roll-out takes that a step higher. Prior to C# 7.3, we could not use ‘==’ and ‘!=’ operators to compare tuples. C# 7.3 improvements makes it possible for us to do the same.
var tuple1 = (3,4);
var tuple2 = (5,6);

if(tuple1 == tuple2)
{
// Do something
}

Generic Constraints

The way I see it, this might turn out one feature which find more fans.  Generics, since its introduction in C# 2.0, was always handicapped by its in ability to constraint the accepted generic type must be an enum.
void TestMethod(TSource param) where TSource : Enum
{
// Do something
}
C# 7.3 also allows you use following constraints
  • unmanaged
  • delegate
That’s it for now, we will explore more features soon.