471,627 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Return whole List from collection class?

I've got a collection class built on System.Collections.CollectionBase,
and I want a property that returns all the objects currently in the
collection, like this:

public Object[] Objects
{
get { return (Object[]) List; }
}

This conversion is illegal however. How shall I write instead?

Gustaf
Jan 26 '06 #1
2 1151
object[] objs = new object[Count];
List.CopyTo(objs, 0);

Jan 26 '06 #2
Gustaf wrote:
I've got a collection class built on System.Collections.CollectionBase,
and I want a property that returns all the objects currently in the
collection, like this:

public Object[] Objects
{
get { return (Object[]) List; }
}

This conversion is illegal however. How shall I write instead?

Gustaf


It seemss as though the InnerList property will give you something you could at
least work with - it returns an ArrayList, which is indeed consists of Objects.
So, what about:

public ArrayList Objects
{
get ( return this.InnerList; }
}

(unless I misunderstand what you are after)

HTH,
-rick-
Jan 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Jon Davis | last post: by
6 posts views Thread by Whoever | last post: by
7 posts views Thread by nafri | last post: by
11 posts views Thread by joey.powell | last post: by
1 post views Thread by tshad | last post: by
6 posts views Thread by David C | last post: by
reply views Thread by leo001 | last post: by

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.