I\'m interested: What is C#\'s analog of std::pair
in C++? I found System.Web.UI.Pair
class, but I\'d prefer something template-based.
Than
Apart from custom class or .Net 4.0 Tuples, since C# 7.0 there is a new feature called ValueTuple, which is a struct that can be used in this case. Instead of writing:
Tuple t = new Tuple("Hello", 4);
and access values through t.Item1
and t.Item2
, you can simply do it like that:
(string message, int count) = ("Hello", 4);
or even:
(var message, var count) = ("Hello", 4);