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.
Thank you!
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.
Thank you!
System.Web.UI
contained thePair
class because it was used heavily in ASP.NET 1.1 as an internal ViewState structure.Update Aug 2017: C# 7.0 / .NET Framework 4.7 provides a syntax to declare a Tuple with named items using the
System.ValueTuple
struct.see MSDN for more syntax examples.
Update Jun 2012:
Tuples
have been a part of .NET since version 4.0.Here is an earlier article describing inclusion in.NET4.0 and support for generics:
I created a C# implementation of Tuples, which solves the problem generically for between two and five values - here's the blog post, which contains a link to the source.
I typically extend the
Tuple
class into my own generic wrapper as follows:and use it like so:
C# has tuples as of version 4.0.
The PowerCollections library (formerly available from Wintellect but now hosted on Codeplex @ http://powercollections.codeplex.com) has a generic Pair structure.
Some answers seem just wrong,
Here is my pair class
Here is some test code: