Discussion:
how best to store these objects?
(too old to reply)
mp
2016-12-11 03:27:09 UTC
Permalink
I have a class cObject that has a property .Views, which is a collection
of 3 different view objects, cPlanView:cView, cElevationView:cView and
cIsometricView:cView.

So I think I want each cObject to have it's own .Views property

Which kind of collection would be best for such a small collection of
items? collection,dictionary,list?

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Arne Vajhøj
2016-12-11 18:51:13 UTC
Permalink
Post by mp
I have a class cObject that has a property .Views, which is a collection
of 3 different view objects, cPlanView:cView, cElevationView:cView and
cIsometricView:cView.
So I think I want each cObject to have it's own .Views property
Which kind of collection would be best for such a small collection of
items? collection,dictionary,list?
List if it is lookup by index 0..COUNT-1
Dictionary if lookup by key

Arne
mp
2016-12-12 18:03:03 UTC
Permalink
Post by Arne Vajhøj
Post by mp
I have a class cObject that has a property .Views, which is a collection
of 3 different view objects, cPlanView:cView, cElevationView:cView and
cIsometricView:cView.
So I think I want each cObject to have it's own .Views property
Which kind of collection would be best for such a small collection of
items? collection,dictionary,list?
List if it is lookup by index 0..COUNT-1
Dictionary if lookup by key
Arne
thank you Arne
here's what i'm trying, obviously it's very very wrong ;-) lol
the help says Dictionary has a property ".Item" to set and return entries
but I don't get that property when I try to use it.
any hints on where i'm going wrong appreciated

namespace BuildingComponentTest
{
class cViews:cBldgComponentGraphical
{
private Dictionary<string, cView> InternalDictionary;

//attempt to make property to return the "PlanView" object
public cPlanView PlanView
{
get { return InternalDictionary.Item("Planview"); }
//no item property appears in intellisense
set { InternalDictionary.Item("PlanView") = value ; }
}

//my first attempt at a constructor
//default constructor
public cViews ()
{
InternalDictionary = new Dictionary<string, cView>();

InternalDictionary.Add("PlanView", new cPlanView());
InternalDictionary.Add("ElevationView", new cElevationView());
InternalDictionary.Add("IsometricView", new cIsometricView());


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
mp
2016-12-12 18:21:22 UTC
Permalink
Post by mp
Post by Arne Vajhøj
Post by mp
I have a class cObject that has a property .Views, which is a collection
of 3 different view objects, cPlanView:cView, cElevationView:cView and
cIsometricView:cView.
So I think I want each cObject to have it's own .Views property
Which kind of collection would be best for such a small collection of
items? collection,dictionary,list?
List if it is lookup by index 0..COUNT-1
Dictionary if lookup by key
Arne
thank you Arne
here's what i'm trying, obviously it's very very wrong ;-) lol
the help says Dictionary has a property ".Item" to set and return entries
but I don't get that property when I try to use it.
any hints on where i'm going wrong appreciated
get { return InternalDictionary.Item("Planview"); }
ok further reading found .Item property is, for whatever reason,
invisible so now using
private Dictionary<string, cView> InternalDictionary;

public cPlanView PlanView
{
get { return InternalDictionary["Planview"]; }
set { InternalDictionary["PlanView"] = value ; }
}
now the error is casting from cPlanView to cView, I thought cPlanView
was a "kind of" cView so thought this would work but obviously not

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
mp
2016-12-12 18:50:20 UTC
Permalink
Post by mp
private Dictionary<string, cView> InternalDictionary;
public cPlanView PlanView
{
get { return InternalDictionary["Planview"]; }
set { InternalDictionary["PlanView"] = value ; }
}
now the error is casting from cPlanView to cView, I thought cPlanView
was a "kind of" cView so thought this would work but obviously not
this seems to have gotten rid of compiler complaints
public cPlanView PlanView
{
get { return(cPlanView) InternalDictionary["Planview"]; }
set { InternalDictionary["PlanView"] = value ; }
}

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Arne Vajhøj
2016-12-13 00:44:34 UTC
Permalink
Post by mp
here's what i'm trying, obviously it's very very wrong ;-) lol
the help says Dictionary has a property ".Item" to set and return entries
but I don't get that property when I try to use it.
any hints on where i'm going wrong appreciated
namespace BuildingComponentTest
{
class cViews:cBldgComponentGraphical
{
private Dictionary<string, cView> InternalDictionary;
//attempt to make property to return the "PlanView" object
public cPlanView PlanView
{
get { return InternalDictionary.Item("Planview"); }
//no item property appears in intellisense
set { InternalDictionary.Item("PlanView") = value ; }
}
You reference Dictionary Item using square brackets not round
round brackets around key.

[] not ().

Arne

Continue reading on narkive:
Loading...