Solved

Read back from dictionary collection c#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check my code out(2) 2 53
fomat Json objects 6 28
Need a complete list of ASP.NET page load events 3 25
Data is not showing from images 15 36
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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.
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: …
A short film showing how OnPage and Connectwise integration works.

943 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

9 Experts available now in Live!

Get 1:1 Help Now