Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling a multi-dimensional data structure in .Net 3.5 and above

Tags:

arrays

.net

I want to build a 2 dimensional (non ragged at this point) object array.

I can easily build a 2 dimensional Array[,], and will do so if it is the best option available, but have tended to avoid arrays in favour of the advanced functionality of .NET's List and Dictionary structures.

I could also use a List<List<T>> to store a 2 dimensional array, but was wondering if there was any best-practice or implemented data structures in .NET 3.5 or above to handle Typed 2 - n dimensional structures with more flexible / comprehensive functionality than an array?

I am not interested in SSAS/OLAP style answers.

like image 699
johnc Avatar asked Dec 07 '25 18:12

johnc


2 Answers

  • A two dimensional array would work really well, it would consume the least amount of ram, and have the fastest lookup times. It would generally work well with read-only data
  • A list of lists, or dictionary of lists, or dictionary of arrays, or dictionary of dictionaries would work well too depending on how you need to access the data etc
like image 131
Alex Black Avatar answered Dec 10 '25 12:12

Alex Black


I'd look at Tuple implementations for .NET 3.5. Tuples will be native in .NET 4.0, so this will be forward compatible:

  • Will a future version of .NET support tuples in C#?
  • Using anonymous types to simulate a tuple (used quite a bit by the MVC devs)
like image 41
Jon Galloway Avatar answered Dec 10 '25 13:12

Jon Galloway



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!