How To Make A Collection Class
Print Hello World
Write Basic Syntax
Use Properties
Make An If Else Ladder
Make A Branch Statement
Declare Inits
Use Lists
Use Arrays
Make A Class Hierarchy
Use Nil And Nilable Types
Use Dynamic Typing
Declare Variable Number Of Args
Read And Write Files
Check Inheritance And Implementation
Customize Object Equality
Pass References To Methods
Translate Pseudo Code To Cobra 1
Translate Pseudo Code To Cobra 2
Implement IEnumerable 1
Implement IEnumerable 2
Iterate Through Recursive Data With Yield
Make A Collection Class
Declare Contracts
Threads
Win Forms
WPF
GTK
Qyoto
Access MySQL
XNA
Open TK
 
"""
MakeACollectionClass.cobra

This HowTo shows the syntax and techniques for declaring a class that
implements IList<of T>.
"""


class MyList<of T> implements IList<of T>

    var _items as List<of T>

    cue init
        base.init
        _items = List<of T>()

    ## IEnumerable ##

    def getEnumerator as IEnumerator<of T>
        return _items.getEnumerator

    def getEnumerator as System.Collections.IEnumerator
        implements System.Collections.IEnumerable
        return .getEnumerator


    ## ICollection ##

    get count as int
        return _items.count

    get isReadOnly as bool
        return false

    def add(item as T)
        _items.add(item)

    def clear
        _items.clear

    def contains(item as T) as bool
        return _items.contains(item)

    def remove(item as T) as bool
        return _items.remove(item)

    def copyTo(array as T[], index as int)
        _items.copyTo(array, index)


    ## IList ##

    pro [index as int] as T
        get
            return _items[index]
        set
            _items[index] = value

    def indexOf(x as T) as int
        return _items.indexOf(x)

    def insert(index as int, x as T)
        _items.insert(index, x)

    def removeAt(index as int)
        _items.removeAt(index)


class Program

    def main
        t = MyList<of int>()
        t.add(5)
        assert t.count==1