473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ArrayList member variable property accessor

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
Nov 16 '05 #1
2 9841
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" <ma*********@311.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #2
TS
thanks, I used your code and it works!!!
"Henk Verhoeven" <henk.verhoeven@_nospam_bluecod.net.nonospam> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
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" <ma*********@311.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm still learning Python as I develop a medium-sized project. From my previous experience with C++, I've burnt into my mind the notion of information hiding. I'm having trouble...
10
by: Chuck | last post by:
Hi! Any ideas as to how I can get ride of the script error undefined variable "Exp_Month"? I am trying to get this drop down list to default to the current month as opposed to 01. Thank...
4
by: Hans De Schrijver | last post by:
I have a private ArrayList variable that holds objects of various types, though they're all derived from a common base class (User). What I would like to do is provide public accessor properties...
10
by: Jeff Grills | last post by:
I am an experienced C++ programmer with over 12 years of development, and I think I know C++ quite well. I'm changing jobs at the moment, and I have about a month between leaving my last job and...
2
by: Adam | last post by:
Hi, I've got a class which contains a number of properties which in turn are read from a database. For example: class TData public property firstName <get and set here> public property...
1
by: RBCC | last post by:
I have the following structure: Structure member Dim name As String Dim phone As String End Structure Dim memberarray As New ArrayList Dim membership As member ******************** Ihave...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
37
by: Joergen Bech | last post by:
(Slightly religious question): Suppose I have the following class: ---snip--- Public Class MyClass Private _MyVariable As Integer Public Property MyVariable() As Integer Get
5
by: TS | last post by:
is it preferred to access member variables directly in code, on the page that declared them, versus going thru a property accessor? I would think that since theres no security concerns or anything...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.