What I just want is to initialize a string[] array constant by specifying not only the values, but the indexes they will be attached to.
For example, on:
private static readonly string[] Pets = new string[] {“Bulldog”, “GreyHound”};
I would like to state that BullDog corresponds to index 29 and GreyHound to 5 (Like php 🙂 )
Any suggestion?
Cheers,
If you have some flexibility in terms of your data structure, it would be more efficient to use a
Dictionary<int, string>instead of an array for this behavior.Example (if you are using C# 3 or above):
Same example for legacy applications: