The data structure of a collection type is an important part of everyday programming, and most business requirements need to be used in the collection type of the dataset. NET platform provides us with a wide range of collection types of data structures, we need to simply call the appropriate API to complete the scattered data collation. This paper collects the present. NET platform to provide us with a small example of all the collection types.
IEnumerable
Namespace System.Collections.Generic
{public
interface ienumerable<out t>: IEnumerable
{
Ienumerator<t> GetEnumerator ();
}
public static void Enumerabletest ()
{
list<string> tmp = new list<string> ();
Tmp. ADD ("Apple");
Tmp. ADD ("Grape");
Tmp. ADD ("watermelon");
strenumerable = tmp as ienumerable<string>;
if (TMP!= null)
{
var iterator=strenumerable.getenumerator ();
while (iterator. MoveNext ())
{
Console.WriteLine (iterator). current);
}
/*output
Apple
Grape
Watermelon
*/
}
ICollection
namespace System.Collections.Generic {public interface icollection<t>: Ienumerable<t>, Ienumer
Able {bool IsReadOnly {get;}
void Clear ();
void CopyTo (t[] array, int arrayindex);
BOOL Remove (T item); }
}
public static void Collectiontest ()
{
list<int> sourcetable=new list<int> ();
Sourcetable.add ();
Sourcetable.add (a);
Sourcetable.add ();
Intcollection = SourceTable as icollection<int>;
if (intcollection!= null)
{
Console.WriteLine ("current collection has {0} elements totally", Intcollection.count);
var iterator = Intcollection.getenumerator ();
while (iterator. MoveNext ())
{
Console.WriteLine (iterator). current);
}
/*out put current
collection has 3 elements totally