Skip to content
David Cumps

Snippets

Part of my 2008 study notes for exam 70-536 (.NET Framework 2.0).

Operator Overloading

struct MyPoint
{
    private int _x;
    private int _y;
 
    public int X
    {
        get { return this._x; }
    }
 
    public int Y
    {
        get { return this._y; }
    }
 
    public MyPoint(int x, int y)
    {
        this._x = x;
        this._y = y;
    }
 
    public static MyPoint operator +(MyPoint a, int b)
    {
        // Returns a new object, conform to the immutability.
        return new MyPoint(a.X + b, a.Y + b);
    }
}

Predicates

static void Main(string[] args)
{
    int[] ar = { 3, 1, 2 };
    Console.WriteLine(Array.TrueForAll<int>(ar, new Predicate<int>(Check))); // Returns False
}
 
static bool Check(int target)
{
    return (target == 3);
}

You May Also Like

ArrayList Class

Resizeable, unordered, index-based collection. Suffers from boxing/unboxing when working with value types. Implements IEnumerator, allowing foreach…

BitArray Class

Contains an array of true/false values. Resizable through the Length property. Supports bitwise operations.