Containing sets of properties in some sort of object -- please help!

  • Thread starter Thread starter almurph
  • Start date Start date
A

almurph

Hi,

I have an object with 3 properties, 2 int arrays and an int. I need
another object to contain a set of these objects i.e something to
consolidate a set of them but able too differenciate between each set.

For example:

First Set:

int[] a
int[] b
int c

Second Set:

int[] d
int[] e
int f


Third Set:
etc
etc
etc

My problem is though I don't know how to do this? Is the best type of
object an indexer? any help/comments/suggestions/code-sampels much
appreciated.

Thanks,
Al.
 
If the "2 int arrays and an int" represents something, then I would
make that a class* by itself, and simply encapsulate a few of them:

public class Foo {
int[] a; // with suitable accessors
int[] b;
int c;
}

class Bar {
// pick more meaningful names...
public Foo FirstSet {get;set;}
public Foo SecondSet {get;set;}
public Foo ThirdSet {get;set;}
}

If the number of Foo instances is indeterminate, then a List<Foo> or
similar would work, and indeed, an indexer may be desirable.

class Bar {
public Bar() {Bar = new List<Foo>();}
public List<Foo> Bar {get;private set;}
}

Marc

*=or /possibly/ a struct - but class should be the default
 
Hi,

        I have an object with 3 properties, 2 int arrays and an int. I need
another object to contain a set of these objects i.e something to
consolidate a set of them but able too differenciate between each set.

        For example:

First Set:

int[] a
int[] b
int c

Second Set:

int[] d
int[] e
int f

Third Set:
etc
etc
etc

        My problem is though I don't know how to do this? Is the best type of
object an indexer? any help/comments/suggestions/code-sampels much
appreciated.

Thanks,
Al.

Hi,
When you say you have an object, are you meaning that you have a class
with three properties as you describe?
If not, you should create such a class.

Then the wrapping class depend of the operations you want to perform
on the collection of the defined class. If all you do is iterate in
the collection then a List<MyClass> is enough.
Otherwise you can have a class that has a collection property (it can
be an indexer) that hold the collection of your defined class.
 
Hi Marc,

Thanks for the reply - yeah I was trying something like this. Once
class encapsulating another class with the properties. However I get
the error message: "member names cannot be the same as their enclosing
type"
at:

public List<Foo> Bar {get;private set;}

Under the word: Bar

Any ideas?
 
Oops! Rename the list property, for example to Items:


Marc

Marc,

Thanks. Working like a charm now. I think I'll modify it to an
indexer, may be slightly more readable.
Thanks again,
Al.
 
Back
Top