473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Array to Dictionary<string, string>

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
2 12814
Curtis Rutland
3,256 Expert 2GB
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
@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

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

Similar topics

19
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not...
0
by: William Stacey [MVP] | last post by:
Trying to figure out Dictionary<> and using CaseInsensitive Comparer<> like I did with normal Hashtable. The Hashtable can take a case insenstive Comparer and a Case insensitive HashCode provider....
7
by: Wilson | last post by:
Hi, How do get the Dictioanry object from FiedlInfo ? my code : fieldInfo = this.GetType().GetField("dictioanry1"); ??Dictionary<string, string> dicTemp1 = (Dictionary<string,...
4
by: Peter K | last post by:
Hi are there any benefits in using StringDictionary over Dictionary<string, string? It appears they achieve the same thing... (I could be wrong of course). thanks, Peter
6
by: daohuy.hua | last post by:
The context is that I have a C# class named MainModel which has a private Dictionary<string, FileStreammember named dict. I also have a property Dict to access to this member: public...
0
by: Andy B | last post by:
Is there a way to databind a checkBoxList to a Dictionary<string, string> object? If so, how do you do it?
2
by: Andy B | last post by:
I don't know if this is even working or not but here is the problem. I have a gridview that I databound to a dictionary<string, stringcollection: Contract StockContract = new Contract();...
4
by: =?Utf-8?B?YW1pcg==?= | last post by:
how can I access the first item of a dictionary where the datatype for the Key is not known to me? I tried the array index 0 and taht did not work because the key is not of integer type. ...
9
by: whosaidwhat | last post by:
Hello, I am creating a program that has a byte used as the key for a Dictionary class. The problem is best described with an example: (C# example of problem) private Dictionary<byte,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.