2

Found this in some api dode. It's not accepted by VS 2015 to have two enums as key, and I've never seen such declaration before. I assume it has worked for whom wrote it, so what should I learn..?

private readonly ConcurrentDictionary<(Pair c, ChannelType o), ClientWebSocket> _wsClients;

Pair and ChannelType are enums.

bretddog
  • 5,411
  • 11
  • 63
  • 111

1 Answers1

3

This is syntax sugar for value tuples introduced in C# 7.0. In this case, it combines two values into a single value. Read more about value tuples in this introduction.

The reason it can be used in a key of a dictionary is that the value is equatable, if each value in the tuple matches the other, it will be consider the same.

For more information about value tuples vs class based tuples, see What's the difference between System.ValueTuple and System.Tuple?

Bas
  • 26,772
  • 8
  • 53
  • 86