System.Collections.API - Core

Introduction

This API provides comprehensive support for working with collections in .NET.

It encompasses essential operations like adding, removing, and iterating through collections, enabling efficient data manipulation and retrieval.

Key Concepts

API Methods

Add(T Item): Adds an item to the collection. Returns the modified collection.

Remove(T Item): Removes an item from the collection. Returns the modified collection, or `null` if the collection is empty.

GetEnumerator(): Returns an iterator for the collection. Used for iterating.

Next(IEnumerator): Executes the iterator and returns the next item.

Count(): Returns the number of items in the collection.

Element(IEnumerator): Returns the next element from the iterator.

Yield(): Pauses execution until the iterator is exhausted.

Example Usage

Here's an example of how to use the API:

            Add a number:  `System.Collections.ArrayList myList = new System.Collections.ArrayList();`
            Add a string:  `System.Collections.List myList = new System.Collections.List();`
            Add a custom object:  `System.Collections.Generic.List myList = new System.Collections.Generic.List();`
            Remove a number: `myList.Remove(5);`
            Remove a string: `myList.Remove("Hello");`
            Iterate through the list: `foreach (var item in myList) { ... }`
            Count the elements: `Console.WriteLine(myList.Count());`
            Get the next element: `var next = myList.GetEnumerator();`
            Next (iterator): `foreach (var item in next) { ... }`
            Count the iterator: `Console.WriteLine(next.Count());`
            Element (iterator): `var element = next.Next(iterator);`
            Yield: `foreach (var item in next) { ... }`