By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

Array to Dictionary<string, string>

P: 12
hi...

can anyone help to show me how to store the array in a dictionary object as shown below?

FROM: Array
[0]: "PARAMETERS"
[1]: "ParamName-1"
[2]: "ParamValue-1"
[3]: "ParamName-2"
[4]: "ParamValue-2"
[5]: "ParamName-3"
[6]: "ParamValue-3"
[7]: "ParamName-4"
[8]: "ParamValue-4"
[9]: "ParamName-n"
[10]: "ParamValue-n"
[11]: "PROCEDURES"
[12]: "ProcName-1"
[13]: "ProcValue-1"
[14]: "ProcName-2"
[15]: "ProcValue-2"
[16]: "ProcName-3"
[17]: "ProcValue-3"
[18]: "ProcName-n"
[19]: "ProcValue-n"

TO: Dictionary<string, string>
Count = 9
[0]: {[ParamName-1, ParamValue-1]}
[1]: {[ParamName-2, ParamValue-2]}
[2]: {[ParamName-3, ParamValue-3]}
[3]: {[ParamName-4, ParamValue-4]}
[4]: {[ParamName-n, ParamValue-n]}
[5]: {[ProcName-1, ProcValue-1]}
[6]: {[ProcName-2, ProcValue-2]}
[7]: {[ProcName-3, ProcValue-3]}
[8]: {[ProcName-n, ProcValue-n]}

thanks a lot..

-jan :)
Jan 5 '09 #1
Share this Question
Share on Google+
2 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
Cant you do a loop like this:
Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i<array.Length; i+=2)
  2.   dict.Add(array[i], array[i-1]);

That should work.
Jan 5 '09 #2

P: 12
@insertAlias
thanks!!

i made a little tweak though :)

Expand|Select|Wrap|Line Numbers
  1. for (int i = 1; i<array.Length; i+=2)
  2. {
  3.    if (array[i].ToString() == "PROCEDURES")
  4.    {
  5.       i = i - 1;
  6.    }
  7.    else
  8.    {
  9.       dict.Add(array[i].ToString(), array[i + 1].ToString());
  10.    }
  11. }
  12.  
Jan 5 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.