Solved

Read back from dictionary collection c#

Posted on 2014-07-20
2
190 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 34

Author Comment

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

Mike
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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