- Feature Articles
-
CodeSOD
- Most Recent Articles
- Brushing Up
- Irritants Make Perls
- Crossly Joined
- My Identification
- Mr Number
- intint
- Empty Reasoning
- Zero Competence
-
Error'd
- Most Recent Articles
- Not Impossible
- Monkeys
- Killing Time
- Hypersensitive
- Infallabella
- Doubled Daniel
- It Figures
- Three Little Nyms
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
ArrayOfKeyValueOfintintKeyValueOfintint[1]=1
Admin
.net 2.0 (2005):
Admin
I once had to do this when dealing with a third-party library. I needed to pass a Map, and in theory that would've worked, but the library added a lot of cruft that I would've had to filter out at the other end. I thought there was probably a way to do it, but I couldn't be bothered to figure it out, so I just flattened the Map to an array, alternating between keys and values.
Admin
Admin
{Evil Grin}
(int Key, int Value)[]
On a serious note - the idea of naming the type is not bad. Just the name used. It probably should have been something like CellData, or whatever is is storing.
Admin
Is this AI?
Admin
Not the same; dictionary doesn't allow duplicate keys ;-)
Addendum 2025-01-02 18:26: Plus you cannot index it by position and the sort order will also be messed up.
Admin
But then DRY so you'd want to type alias it, and that alias would be
ArrayOfKeyValuePairOfintint
. And then, to not forget the thing is actually an array, you'd not put the array part into the alias. Just a brilliant naming scheme! CQFD.Admin
Finally a reason to switch to 32:9 monitors.
Admin
Isn't this basically the type equivalent of #define ONE=1 ?
The intent of having a custom type is to help provide a meaningful name to the otherwise generic (magic) type, much as how using a constant is supposed to help provide a meaningful name to the otherwise (generic) magic number.
Doing this doesn't tell us anything about the nature of the values that it expects, only (misleadingly?) about the structure of the data. Is it an array because it may hold any number of values, or does the fact that it mentions "KeyValueOfIntint" twice imply that it's strictly length 2, each item containing a KeyValueOfIntint (where there could be other types with different pairs of inner types)? I'm hoping at least that these types are auto-generated; but then I don't know that that's a good thing either. At least the parameter has a reasonably descriptive name. Certainly a good WTF because it piques one's curiosity (in a good thriller film sort of way) as to what else lurks around the corner.