-2

I'm refactoring some legacy code that uses a 2D string array:

/// <summary>Array of valid server messages</summary>
private static string[,] serverRsp =
{
    {"JOIN",            "RSP" }, 
    {"SETTING",     "RSP" }, 
    . . .

I want to modernize this, but don't know if I should use a Dictionary, a List of list of string, or something else. Is there a standard correlation between the "olden" way and the golden way (legacy vs. refactored)?

IWBN (it would be nice) if there was a chart somewhere that showed the olden vs. the golden for data types and structures, etc.

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

1 Answers1

3

[,] is not an "old" datastructure, and hopefully will never become. Keep using it whenever appropriate.

For example:

  1. just in this case have a List<List<T>> is much more confusing then having simple 2 dimensional array.

  2. It's lighter then List<T>in terms of memory consumption (at least from my measurements).

In short: if there is no any real reason, or new requirement to change it, like make it faster O(1) access data structure key-value store (for non index, hence key like, fast access), do not change it. It is clear and it is readable.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Tigran
  • 61,654
  • 8
  • 86
  • 123