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.

1 Answer 1

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.