473,225 Members | 1,394 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,225 software developers and data experts.

About interface ICollection

Hello!

I'm reading in book and it says the following.
"ICollection provides the ability to obtain the number of items in a
collection and to copy items into
a simple array type(inherits from IEnumerable)."

I have looked in interface ICollection and IEnumerable and there is no
method or property that
match in any way the last part of the statement from the book that says
"copy items into
a simple array type"

//Tony
Jun 27 '08 #1
3 1984
Well, I'm not sure why it mentions "inherits from IEnumerable", since
that doesn't add anything here - but the answer is CopyTo:

ICollection data = new int[] { 1, 2, 3, 4, 5 };
int[] copy = new int[data.Count];
data.CopyTo(copy, 0);

Of course, in .NET 2.0 and above it would be preferable to use the
genric (typed) interfaces:

ICollection<intdata ...

This makes it more explicit that it expects CopyTo to operate on an
int[], rather than just an Array - and a lot of other things.

Marc
Jun 27 '08 #2
On Tue, 10 Jun 2008 00:24:57 -0700, Tony <jo*****************@telia.com>
wrote:
Hello!

I'm reading in book and it says the following.
"ICollection provides the ability to obtain the number of items in a
collection and to copy items into
a simple array type(inherits from IEnumerable)."

I have looked in interface ICollection and IEnumerable and there is no
method or property that
match in any way the last part of the statement from the book that says
"copy items into
a simple array type"
As has been the case with every other question you've posted of this
nature, it is impossible to provide any real insight as to what the text
might mean, given that we are not in possession of the text and have no
context.

That said, it seems to me that ICollection.CopyTo() is a method that meets
the book's description exactly, at least as far as is possible to tell
from what little context we do have. :)

Pete
Jun 27 '08 #3
On Jun 10, 3:24*am, "Tony" <johansson.anders...@telia.comwrote:
Hello!

I'm reading in book and it says the following.
"ICollection provides the ability to obtain the number of items in a
collection and to copy items into
a simple array type(inherits from IEnumerable)."
ICollection.Count does the counting part
ICollection.CopyTo does the copy part

I do not what CopyTo has to do with IEnumerable though.
Jun 27 '08 #4

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

Similar topics

5
by: Jimski | last post by:
Hi, I am creating a model to navigate a tree of symbols and links. My main purpose of this post is to ascertain the quickest way of navigating the tree. There are two ways that I am considering,...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
2
by: PMarino | last post by:
Hi all - I'm sure I'm being brain-dead here - and I think the answer is 'you can't do that', but I thought I would try. I have an interface that is Generic, with two type arguments. I want to...
3
by: Rafael Tejera | last post by:
I would like to create an history module to my application.. I need some advice to use a duplicate database with who, when and where fields added to that new duplicate table, or create a table...
6
by: Doug | last post by:
Hi, I want to create a collection of objects that will be used as a property of another object. So for example if I had a Customer object, I would like to have an AddressCollection property...
1
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I am confused: Question 1: the online help for the Stack class reads: Public Class Stack Implements ICollection, IEnumerable, ICloneable However the members of ICollection do not show up as...
1
by: Larry | last post by:
I checked definition of class CollectionBase public abstract class CollectionBase : IList, ICollection, IEnumerable, it implements 3 interface IList, ICollection and IEnumerable. I found...
2
by: Tony | last post by:
Hello! According to the documentation we have the following interface IList : ICollection, IEnumerable { I can understand all the methods in this IList } interface ICollection : IEnumerable...
6
by: Mike P | last post by:
I am looking through some code and have found a lot of methods that return an interface such as ICollection. What is the reason for this? If you return ICollection, does that mean that you can...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.