[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

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.
0
Mike Eghtebas
Asked:
Mike Eghtebas
  • 2
  • 2
1 Solution
 
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
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now