ArrayList member variable property accessor

  • Thread starter Thread starter TS
  • Start date Start date
T

TS

Hello, I am trying to have a member of a class declared as an arrayList to
have get & set property accessors, but I can't get it to compile. This
member variable can't be a simple array because I don't know the number of
items in the collection. I need to be able to add more items at run time.

Any solutions?

thanks
 
Hi TS

Post some code, there should be no reason for it to compile.

Internally you can manage an array list, but you can make your member
property to return a typed array if you want

Example:
private ArrayList alEmployees = new ArrayList(20) ;

Public Employee[] Employees {
get {
return (Employee[])alEmployees.ToArray
(typeof(Employee))
}
set {
alEmployees.clear();
alEmployees.AddRange(vaue);
}
}

This is assuming you do want a typed array, otherwise using the arraylist
should do the trick

private ArrayList alEmployees = new ArrayList(20) ;

Public ArrayList Employees {
get {
return this.alEmployees; }
set {
this.alEmployees = value ;
}
}

Give some code excample if this is not quite what you had in mind

Henk
 
thanks, I used your code and it works!!!


Henk Verhoeven said:
Hi TS

Post some code, there should be no reason for it to compile.

Internally you can manage an array list, but you can make your member
property to return a typed array if you want

Example:
private ArrayList alEmployees = new ArrayList(20) ;

Public Employee[] Employees {
get {
return (Employee[])alEmployees.ToArray
(typeof(Employee))
}
set {
alEmployees.clear();
alEmployees.AddRange(vaue);
}
}

This is assuming you do want a typed array, otherwise using the arraylist
should do the trick

private ArrayList alEmployees = new ArrayList(20) ;

Public ArrayList Employees {
get {
return this.alEmployees; }
set {
this.alEmployees = value ;
}
}

Give some code excample if this is not quite what you had in mind

Henk
TS said:
Hello, I am trying to have a member of a class declared as an arrayList to
have get & set property accessors, but I can't get it to compile. This
member variable can't be a simple array because I don't know the number of
items in the collection. I need to be able to add more items at run time.

Any solutions?

thanks
 
Back
Top