So far I always used an interface for my message contracts:
In combination with anonymous types, you don’t even need to implement this interface yourself but create an anonymous type on the fly that will be published:
Let’s see if we can do the same thing by using a record type instead. Here is our rewritten message contract:
We could publish the message in the same way as before:
BUT you can also take advantage of the "target-typing" feature in C# 9, this allows us to create a specific instance of the record type instead of an anonymous type:
Did you notice the difference? We call the constructor of the record type through the 'new ()' syntax.