This week I was working on a project and came across a class I’d never used in C# called a Triplet. You can look up the Triplet on MSDN here.
The Triplet is just a class with three properties: First, Second, and Third. Each of the properties holds an instance of an object. That’s it. That’s all this thing does. The very first thing I noticed once I saw what it did was the namespace it’s in. You’d think it would be in System.Collections, or System.Collections.Specialized or something, but no… it’s it System.Web.UI along with things like the System.Web.UI.Control class. WTFBBQ?
I would love to hear a rational explanation for this. I am pretty anal about namespacing and I don’t like having to stretch the tasteful bounds of a namespace to put something in. I will on occasion, but this is a bit much.
I downloaded Reflector to see if I could find any other gems stored in that namespace. Lo and behold… I find Pair. Care to guess what Pair is? Exactly.. it’s the same as Triplet… but with…. TWO properties.
Up
on obsessing over this I started to think about why these classes even exist at all. What is wrong with object[] objArray = new object[2]; ? Is that so complicated that there needs to be a type, and a horribly misplaced type at that?
In lieu of my findings I have created the following class I want added to the .NET Framework …. The Duodecuple.
1: using System;
2: //Stay consistent with completely nonsensical namespacing namespace System.Workflow.Runtime.DebugEngine
3: {
4: // that's "12" for those of you who don't feel like going to wikipedia
5: public class Duodecuple
6: {
7: public object First { get; set; }
8: public object Second { get; set; }
9: public object Third { get; set; }
10: public object Fourth { get; set; }
11: public object Fifth { get; set; }
12: public object Sixth { get; set; }
13: public object Seventh { get; set; }
14: public object Eighth { get; set; }
15: public object Ninth { get; set; }
16: public object Tenth { get; set; }
17: public object Eleventh { get; set; }
18: public object Twelfth { get; set; }
19: ///
20: /// Constructor. Since we're taling C# 3.5+ here you can just
21: /// instantiate with ... new Duodecuple { First = whatever, Second = anotherObject };
22: /// No sense in having all those constructors
23: ///
24: public Duodecuple (){}
25: } }
you're welcome.
-Mike