What is a ICollection in C#?
private void SendEmail(string host, int port,
string username, string password,
string from, string to,
string subject, string body,
ICollection<string> attachedFiles)
The ICollection<T>
interface is the base interface for classes in the System.Collections.Generic
namespace.
The ICollection<T>
interface extends IEnumerable<T>
and is extended by IDictionary<TKey, TValue>
and IList<T>
.
An IDictionary<TKey, TValue>
implementation is a collection of key/value pairs, like the Dictionary<TKey, TValue>
class.
An IList<T>
implementation is a collection of values, and its members can be accessed by index, like the List<T>
class.
http://msdn.microsoft.com/en-us/library/92t2ye13.aspx
I think what the OP is actually trying to understand, is what implements ICollection<string>
, as obviously new ICollection<string>()
isn't going to fly.
As Micah pointed out, List<string>
implements ICollection<string>
. If you want to know what else does, take a look at ILSpy, and find the ICollection<T>
type, analyze it, and see what implements it. Here are some of my results
... and more
Also, a plain ol' string
array also implements ICollection<string>
ICollection is a interface that represents a collection, it also contains strongly typed members
Here is an example of how to implement that interface
http://support.microsoft.com/kb/307484
The Generic List Implements this interface
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
A collection is a group of objects that have the same type (string in your example).
From the documentation:
Objects of any type can be grouped into a single collection of the type Object to take advantage of constructs that are inherent in the language. For example, the C# foreach statement (for each in Visual Basic) expects all objects in the collection to be of a single type.
ICollection is the interface definition for a collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With