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

℡╲_俬逩灬. 提交于 2019-12-04 03:22:54

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5702396/what-is-the-triplet-class-used-for-is-it-related-to-tuples

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!