Solved

Read back from dictionary collection c#

Posted on 2014-07-20
2
181 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
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 33

Author Comment

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

Mike
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now