Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do i convert arraylist to List<Dictionary<string, string>>

Posted on 2009-12-24
4
Medium Priority
?
3,440 Views
Last Modified: 2012-06-21
Hello,
The following is the code from my service.  I need to convert arraylist into
Dictionary<string, string>. The arraylist is in key/value.

E.g. Sample arraylist as follows:

array list (0): "UserID"
array list (1): "Tom"
array list (2): "ActivityName"
array list (3): "Login"

*********  Service code *********************
  public class Service1 : System.Web.Services.WebService
    {

        protected List<Dictionary<string, string>> list;
        protected String activityname;
       
        [WebMethod]
        public void WriteToBam(string ActivityName, object[] arrObj)
        {
             ArrayList arrDB = new ArrayList(ar rObj);
            // Load the value from arraylist to Dictionary (key/value)

             BAMWriter bamWriter = new BAMWriter();
            bamWriter.writeToBamDatabase(list, ActivityName);
        }
    }

Thanks in advance
0
Comment
Question by:Lalu01
4 Comments
 
LVL 30

Expert Comment

by:Reza Rad
ID: 26121533
do you have multiple arraylists or you have one arraylist and on each item of this arraylist you have another arraylist.
could you attach the code of creating your arraylist here
0
 
LVL 8

Accepted Solution

by:
Thejaka earned 500 total points
ID: 26121562

// Will this work?
//
for (int i=0; i<arrObj.Count; i+=2)
  list.Add(Convert.ToString(arrObj[i]), Convert.ToString(arrObj[i+1]))

Open in new window

0
 
LVL 11

Expert Comment

by:lenordiste
ID: 26122748
not sure what you are trying to achieve but your code seems to indicate you have an array of object that you use to create an arraylist to create a dictionnary.
one thing you can do is use the function ToDictionnary of your object array to get your dictionnary right away.
here is an example:
Dictionary<string,string> myDict =arrObj.ToDictionary(key => key.ToString(), value => value.ToString());

you ll probably have to change the lambda expressions for key and value to match what your data structure actually holds.
0
 

Author Closing Comment

by:Lalu01
ID: 31669902
Thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question