1

I have these arrays

int[] ivrArray = { 1, 0, 0, 0};
int[] agentsArray = { 0, 2, 0, 0 };
int[] abandonedArray = { 0, 0, 3, 0};
int[] canceledArray = { 0, 0, 0, 4};

and I used this dictionary:

 Dictionary<string, int[][]> dictionary = new Dictionary<string, int[][]>
            {
                {"IVR", ivrArray.Select(_ => new[] {_}).ToArray()},
                {"Agents", agentsArray.Select(_ => new[] {_}).ToArray()},
                {"Abandoned", abandonedArray.Select(_ => new[] {_}).ToArray()},
                { "Cancelled",canceledArray.Select(_ => new[] {_}).ToArray()}
            };

the result after changing it to json is:

{
  "IVR": [
    [1],
    [0],
    [0],
    [0]
  ],
  "Agents": [
    [0],
    [2],
    [0],
    [0]
  ],
  "Abandoned": [
    [0],
    [0],
    [3],
    [0]
  ],
  "Cancelled": [
    [0],
    [0],
    [0],
    [4]
  ]
}

you can see that each element in the JSON is array like this [[0],[0],[0],[4]]

I need to add another value to each element in that array, so the result will be this:

[[1325376000000,0],[1328054400000,0],[1330560000000,0],[1333238400000,0]]

How can I do that?

These values are static for all the four arrays.

9
  • 1
    Didn't you asked amost the same quesiton 2 hours ago? stackoverflow.com/questions/23028526/… Commented Apr 12, 2014 at 11:26
  • And aside from that, it really feels like you should be creating a new type with properties for IVR, agents, abandoned etc. Then you could just have one collection. Commented Apr 12, 2014 at 11:27
  • Just add other value when you create the array: new[] {otherValue, _} Commented Apr 12, 2014 at 11:28
  • @SonerGönül no that is a completely differenct question Commented Apr 12, 2014 at 11:32
  • @sjkm could you give me an answer with that please? Commented Apr 12, 2014 at 11:33

3 Answers 3

1

Just add another value when you create the array: new[] {otherValue, _}

Sign up to request clarification or add additional context in comments.

Comments

1

do it like this:

dictionary.Add("new values", new[] 
                             { 
                               new[] {123, 0}, 
                               new[] {123, 0}, 
                               new[] {123, 0}, 
                               new[] {123, 0}
                              });

1 Comment

so I need to do that for the four elements which are ivr, agents, abandont and canceled, isn't there a generic way to do that? like the one I gave in the question
1

JSON serializers will serialize List<T> as JSON arrays, thus using lists will be better than arrays of arrays.

Your dictionary should be Dictionary<string, List<List<int>>>, and you'll be able to obtain a sub-list and add items:

dict["some"][0].Add(0);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.