Mike Eghtebas
asked on
collection. c#
I have the following data:
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:
Question: How can I code this in
private void populeteCriteriaTable(Coll ection coll)
{
}
Thank you.
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
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;
}
}
}
Question: How can I code this in
private void populeteCriteriaTable(Coll
{
}
Thank you.
ASKER
Thank you for the link. I will go and read through to see how it is done.
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
public class CriteriaCollection
{
...
}
really should be renamed to:
public class Criteria
{
...
}
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")
Then, I need to instantiate and store them in a collection object where I can call them by usingmyCollection("criteriaLeft
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
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>