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?
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?
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. TheSavePageViewState()
method starts by creating aTriplet
that contains the following three items:
- 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.
- The collective view state of the
Page
's control hierarchy.- 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.
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.