Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

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.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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>
Avatar of Mike Eghtebas

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.