C# Language Specification



Download 0,75 Mb.
bet30/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   26   27   28   29   30   31   32   33   ...   524
Bog'liq
CSharp Language Specification

Other function members


Members that contain executable code are collectively known as the function members of a class. The preceding section describes methods, which are the primary kind of function members. This section describes the other kinds of function members supported by C#: constructors, properties, indexers, events, operators, and destructors.

The following table shows a generic class called List, which implements a growable list of objects. The class contains several examples of the most common kinds of function members.



public class List
{

const int defaultCapacity = 4;

Constant

T[] items;
int count;

Fields

public List(int capacity = defaultCapacity) {
items = new T[capacity];
}

Constructors

public int Count {
get { return count; }
}

public int Capacity {


get {
return items.Length;
}
set {
if (value < count) value = count;
if (value != items.Length) {
T[] newItems = new T[value];
Array.Copy(items, 0, newItems, 0, count);
items = newItems;
}
}
}

Properties



public T this[int index] {
get {
return items[index];
}
set {
items[index] = value;
OnChanged();
}
}

Indexer

public void Add(T 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;
}
}
return true;
}

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. Download 0,75 Mb.

          Do'stlaringiz bilan baham:
1   ...   26   27   28   29   30   31   32   33   ...   524




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish