Solved

Read back from dictionary collection c#

Posted on 2014-07-20
2
191 Views
Last Modified: 2014-07-20
In the code below, after storing some data into 5 objects, I have stored them in a dictionary object using sting keys.

                RodCriteria criteriaLeft= new RodCriteria("CriteriaLeft",101,2,"2014");
                RodCriteria criteriaRight= new RodCriteria("criteriaRight",105,2,"2014");
                RodCriteria criteriaSide= new RodCriteria("criteriaSide",121,2,"2014");
                RodCriteria criteriaGeneral= new RodCriteria("criteriaGeneral",200,2,"2014");
                RodCriteria criteriaDef= new RodCriteria("criteriaDef",100,1,"2014");

                Dictionary<string, RodCriteria> CriteriaCollection = new Dictionary<string, RodCriteria>();
                CriteriaCollection["criteriaLeft"]=criteriaLeft;
                CriteriaCollection["criteriaRight"]=criteriaRight;
                CriteriaCollection["[b]criteriaSide[/b]"]=[b]criteriaSide[/b];
                CriteriaCollection["criteriaGeneral"]=criteriaGeneral;
                CriteriaCollection["criteriaDef"]=criteriaDef;

Open in new window

Now, starting with the dictionary CriteriaCollection and having a key string such as criteriaSide, I want to read back its date as I had them in:

RodCriteria criteriaSide= new RodCriteria("criteriaSide",121,2,"2014");


This should give me:

"criteriaSide"
121
2
2014

Question: How can I do this?

Thank you.
0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 500 total points
ID: 40207738
See: http://www.dotnetperls.com/dictionary

To read from the dictionary use the index syntax with the key:
RodCriteria ReadFromDict = CriteriaCollection["criteriaSide"];

Open in new window

Now whatever fields or properties of a RodCreteria Type caontain the values 121,2, and"2014" contain them again

Bye, Olaf.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40207751
Thank you very much,

Mike
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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