|
1. System. Object sinfi va uning usullari Umumlashtirish
|
bet | 12/12 | Sana | 18.05.2024 | Hajmi | 70,5 Kb. | | #241174 |
Bog'liq 22-09MemberwiseClone()
Ushbu usul operativ xotirada ushbu turdagi ob'ekt egallagan maydonga yana bir havola yaratish uchun mo'ljallangan. Ushbu usulni ortiqcha yuklash mumkin emas. Agar siz RAMda ob'ektning to'liq nusxasini yaratishni qo'llab-quvvatlashni amalga oshirishingiz kerak bo'lsa, ICloneable interfeysini qo'llab-quvvatlashingiz kerak.
|
Quyidagi misol sanab o'tilgan usullardan ba'zilarining imkoniyatlarini ko'rsatadi.
using System;
namespace Test
{
//*******************************************************
class ObjTest
{
}
//*******************************************************
class App
{
static void Main()
{
// Uyumda ob'ekt yarating
ObjTest obj1 = new ObjTest();
// Usullar bo'yicha qaytarilgan ma'lumotlarni ko'rsatish
// System.Object bazaviy sinfi
Console.WriteLine("ToString(): {0}",
obj1.ToString());
Console.WriteLine("GetHashCode(): {0}",
obj1.GetHashCode());
Console.WriteLine("GetType(): {0}",
obj1.GetType().ToString());
// Obj1 ga yana ikkita havola yarating
ObjTest obj2 = obj1;
object obj3 = obj2;
// Barcha uchta havolaning haqiqiyligini tekshiring
// RAMning bir xil maydoniga ishora
if(obj1.Equals(obj2) && obj2.Equals(obj3))
Console.WriteLine("Xotira manzillari mos keladi ");
while(true);
}
}
}
Listing 11.16. System.Object klassi usullarining imkoniyatlarini namoyish qilish.
Ekran natijalari
ToString(): Test.ObjTest
GetHashCode(): 2
GetType(): Test.ObjTest
Xotira manzillari mos keladi
http://fayllar.org
|
| |