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

Ask A Question

Stats

  • Questions 143k
  • Answers 143k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In C#, you use dictionaries to associate values with strings. May 12, 2026 at 8:27 am
  • Editorial Team
    Editorial Team added an answer From: http://code.google.com/apis/maps/documentation/reference.html#GLatLng GLatLng.distanceFrom( other:GLatLng, radius?:Number ); Returns the distance, in… May 12, 2026 at 8:27 am
  • Editorial Team
    Editorial Team added an answer I think you could. The language seems well suited for… May 12, 2026 at 8:27 am

Related Questions

I am in the process of writing an enterprise-level application utilizing WCF and NetTCP
So I'm trying to create a simple multi-threaded game engine for the game I
OK, so I have a very large multi-threaded unmanaged c++ application (server) that runs
We are an all Unix shop (Solaris, Linux). This last product cycle I returned

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.