Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Triplet class used for? Is it related to Tuples?

Tags:

c#

asp.net

tuples

So I just learnt about the Triplet class. I have no experience with ASP.NET, only the core .NET Framework.

Can someone explain to me where/why the Triplet class exists? Is it like a Tuple?

like image 895
William Mioch Avatar asked Apr 18 '11 11:04

William Mioch


2 Answers

Yes, it's pretty much like Tuple from .NET 4.0, but dates back to .NET 1.0 and ASP.NET 1.0 in particular. It's primarily used in ViewState serialization:

The Page class contains a SavePageViewState(), which is invoked during the page life cycle's save view state stage. The SavePageViewState() method starts by creating a Triplet that contains the following three items:

  1. The page's hash code. This hash code is used to ensure that the view state hasn't been #tampered with between postbacks. We'll talk more about view state hashing in the "View State and Security Implications" section.
  2. The collective view state of the Page's control hierarchy.
  3. An ArrayList of controls in the control hierarchy that need to be explicitly invoked by the page class during the raise postback event stage of the life cycle.

There's also its' younger brother called Pair.

There's absolutely no reason you should even bother about these classes or else an unholy untyped mess will ensue.

like image 117
Anton Gogolev Avatar answered Sep 20 '22 10:09

Anton Gogolev


Sounds like it's got one more object than a Pair. You use it when you need to return exactly three items.

C# and Java are different from Python, which will convert multiple return values into a tuple.

A Triple does sound like a tuple to me - one that has exactly three items.

like image 28
duffymo Avatar answered Sep 19 '22 10:09

duffymo