X hits on this document

1078 views

0 shares

0 downloads

0 comments

35 / 396

C# LANGUAGE SPECIFICATION

public void Add(object item) { if (count == Capacity) Capacity = count * 2; items[count] = item; count++; OnChanged(); }

protected virtual void OnChanged() { if (Changed != null) Changed(this, EventArgs.Empty); }

public override bool Equals(object other) { return Equals(this, other as List); }

static bool Equals(List a, List b) { if (a == null) return b == null; if (b == null || a.count != b.count) return false; for (int i = 0; i < a.count; i++) { if (!object.Equals(a.items[i], b.items[i])) { return false; } } }

Methods

public event EventHandler Changed;

Event

public static bool operator ==(List a, List b) { return Equals(a, b); }

public static bool operator !=(List a, List b) { return !Equals(a, b); }

Operators

}

1.6.6.1 Constructors

C# supports both instance and static constructors. An instance constructor is a member that implements the actions required to initialize an instance of a class. A static constructor is a member that implements the actions required to initialize a class itself when it is first loaded.

A constructor is declared like a method with no return type and the same name as the containing class. If a constructor declaration includes a static modifier, it declares a static constructor. Otherwise, it declares an instance constructor.

Instance constructors can be overloaded. For example, the List class declares two instance constructors, one with no parameters and one that takes an int parameter. Instance constructors are invoked using the new operator. The following statements allocate two List instances using each of the constructors of the List class.

List list1 = new List(); List list2 = new List(10);

Unlike other members, instance constructors are not inherited, and a class has no instance constructors other than those actually declared in the class. If no instance constructor is supplied for a class, then an empty one with no parameters is automatically provided.

1.6.6.2 Properties

22Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views1078
Page views1078
Page last viewedSun Dec 11 05:04:31 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments