collection. c#

I have the following data:
                    1              2                    3               4             5
Criteria Type	CriteriaLeft	CriteriaRight	CriteriaSide	CriteriaGeneral   CriteriaDef
MetricID	  101	          105	          121	               200          100
RegionId	   2	           2	          2	                2               1
YYYY	         2014	          2014	          2014	             2014          2014

Open in new window


I want to instantiate a collection and store 5 objects in it where later on I can retrieve them by calling myColl("CriteriaLeft"), etc. The class I have prepared is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ASPChartComparision
{

	public class CriteriaCollection
	{
        public string CriteriaType { get; set; }
		public int RegionId {get; set;}
		public int MetricId {get; set;}
		public string YYYY {get; set;}
        public CriteriaCollection(string criteriaType, int regionId, int metricId, string yyyy)
		{
            CriteriaType = criteriaType;
			RegionId = regionId;
			MetricId = metricId;
			YYYY = yyyy;
		}
	}
}

Open in new window


Question: How can I code this in

private void populeteCriteriaTable(Collection coll)
{

}

Thank you.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
the class you have prepared is for 1 single "record": the CriteriaCollection is not appropriate, it may be CriteriaRecord
what you need to do "on top" is a collection of those class objects, for example a Dictionary using that type:
http://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.110%29.aspx
the c# code snippet is not really "clear" for your case:
http://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-3 

instead of Dictionary<string, string> it would be Dictionary<string, CriteriaRecord>
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you for the link. I will go and read through to see how it is done.
public class CriteriaCollection
{
...
}
really should be renamed to:
public class Criteria
{
...
}

Open in new window

Then, I need to instantiate it and store like:

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

Open in new window

Then, I need to instantiate and store them in a collection object where I can call them by using

myCollection("criteriaLeft")    to cycle though and read its data.

I hope, this makes it a bit clear and changes your mind to give me workable code. I know the general direction but going from vb to c# I need some help.

Thank you,

Mike
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Criteria criteriaLeft= new Criteria("CriteriaLeft",101,2,"2014")
Criteria criteriaRight= new Criteria("criteriaRight",105,2,"2014")
Criteria criteriaSide= new Criteria("criteriaSide",121,2,"2014")
Criteria criteriaGeneral= new Criteria("criteriaGeneral",200,2,"2014")
Criteria criteriaDef= new Criteria("criteriaDef",100,1,"2014")

Dictionary<string, Criteria> CriteriaCollection= new Dictionary<string, Criteria>();
CriteriaCollection.Add( criteriaLeft.CriteriaType , criteriaLeft);
CriteriaCollection.Add( criteriaRight.CriteriaType , criteriaRight);
CriteriaCollection.Add( criteriaSide.CriteriaType , criteriaSide);
CriteriaCollection.Add( criteriaGeneral.CriteriaType , criteriaGeneral);
CriteriaCollection.Add( criteriaDef.CriteriaType , criteriaDef);

Open in new window



from there, you can access the collection:
CriteriaCollection["criteriaRight"]  which returns the Criteria object
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.