Sinfning statistik elementlari.
Siz sinf elementini yo statistik (statistic member), yo nusxa(instance
member) qilib aniqlashingiz mumkin. Bu shuni anglatadiki, har bir sinf nusxasi
uchun har bir element nusxalanadi. Agar siz elementni statistic deb e‘lon
qilsangiz undan faqat birta nusxa olinadi. Statistic element dastur joriy sinfni
ishga tushirganidan boshlab to dastur yakunlanganicha “yashaydi”. Masalan:
using System;
class InstCount{
public InstCount IS
}
instanceCount++;
static public int instanceCount; //instanceCount = 0;
class AppClass {
public static void Main() {
Console.WriteLine(InstCount.instanceCount)
InstCount ic1 = new InstCount ();
Console.WriteLine(InstCount.instanceCount);
InstCount ic2 = new InstCount ();
Console.WriteLine(InstCount.instanceCount) ; }
Do'stlaringiz bilan baham: |