Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 141341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:45:39+00:00 2026-05-11T07:45:39+00:00

I have what amounts to a multi-dimensional array. int[][][] MyValues; What I want is

  • 0

I have what amounts to a multi-dimensional array.

int[][][] MyValues; 

What I want is to access the indexes via a strongly typed equivelent, such as an enumeration. I’m aware that you can get the enumeration values from the Enum type, but it’s a bit long winded for my tastes.

I’d rather have a way to Strongly type the indexes.

For example:

int CarNumber = MyValues[Racetrack.Daytona][Race.Daytona500][Driver.JGordon]; 

This would, by virtue of it being enum-like, prevent any out of bounds exceptions from being thrown, plus it gives all the indexes a nice human readable meaning.

I’ve implemented this using a dictionary approach, but it seems kind of heavy handed:

Dictionary<Racetrack,Dictionary<Race,<Dictionary<Driver,int>>> =     new Dictionary<Racetrack,Dictionary<Race,<Dictionary<Driver,int>>>(); 

which I can then access via enums, but I don’t really like this approach. It seems ‘ugly’.

I’m looking for some alternate methods to represent what is essentially a multi-dimensional array while using human readable indexers, while maintaining type safety (can’t accidently use a Driver for a Race, for instance, so simply using consts is not a good approach).

Any suggestions?

This will be a compile time array (example above is not real, just an illustration) so I don’t have to worry about inserts or deletes or other manipulations of the array. It will stay immutable, both in values, size and layout.

Using a static class with const values is not a good approach either, since it doesn’t enforce that only the set of values defined can be passed as indexers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:45:40+00:00Added an answer on May 11, 2026 at 7:45 am

    It sounds to me that you want to use indexers rather than an array. Assuming the following enums (Formula 1 based!):

    public enum Track {     Spielberg,     Adelaide,     Casablanca,     Liverpool,     Melbourne,     Berlin,     Sakhir, }  public enum Constructor {     BMW,     Ferrari,     McLaren,     Toyota,     Williams }  public enum Driver {     Hamilton,     Kovalainen,     Raikkonen,     Nakajima,     Glock } 

    the basic structure is as follows:

    public class Race {     int Year { get; set; }     Track Track { get; set; }     Driver[] Placings { get; set; }     public int this[Driver driver] { } // placing by driver }  public class Results {     YearResults this[int index] { }     DriverResults this[Driver index] { }     TrackResults this[Track index] { }     ConstructorResults this[Constructor index] { } }  public class YearResults {     YearDriverResults this[Driver index] { } } 

    This of course is a partial implementation but you can do some pretty cool things with indexers this way. Like you can access your information with any combination of values in any order (assuming you set up all the intermediate classes).

    Its wordier than a multidimensional array or a tuple-keyed Dictionary but I think will give you far more elegant code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is basically a restatement of this question: Java: Multi-dimensional array vs. One-dimensional but
I have a large amount of text in a UITextView. I want to let
I got the following problem: I have an array of char pointers char *opts[]
I have a multi-threaded application build in C# using VS2010 Professional. It's quite a
We have a Swing app that processes relatively large amounts of data. For instance
Let's say I have a class like so: class Gerbil{ int id; float x,y,z;
I have an Java application for copying large amounts of data from users' workstations
I have an app where I import a bunch of data and I want
I want to have generalised email templates. Currently I have multiple email templates with
I have what amounts to a menu page in my Silverlight application. It has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.