|
Mirzo Ulug‘bek nomidagi O‘zbekiston Milliy universiteti Amaliy matematika va intellektual texnologiyalar
|
bet | 6/7 | Sana | 19.01.2024 | Hajmi | 293,8 Kb. | | #141255 |
Bog'liq Ibrohimova Sumayya Hamza qiziAnonim metod cheklovlari:
delegate operatoridan foydalanishda parametrlarni tashlab ketish ham mumkin. Bunday holatda siz ixtiyoriy parametrlarni yuborish imkoniyatiga ega bo'lasiz:
Action SayHello = delegate { Console.WriteLine("Hello!"); };
SayHello();
Action introduce = delegate { Console.WriteLine("This method can be called with any parameters!"); };
introduce(42, 2.7, 2>4, "Hello");
C# 9.0 dan boshlab siz Anonim metodlarni static holatda e'lon qilishingiz mumkin:
Func degree = static delegate (int a, int b)
{
return Math.Pow(a, b);
};
degree(2, 3);
Shuningdek Anonim metodlar Event Handler sifatida ham ishlatilishi mumkin:
saveButton.Click += delegate(Object o, EventArgs e)
{
//some code for saving
System.Windows.Forms.MessageBox.Show("Save Successfully!");
};
C++ Method (Sinf/Class)
Method sinfga tegishli funksiyalardir. Sinfga tegishli funksiyalarni aniqlash uchun ikki yo'l mavjud.
Ichki sinf ta'rifi
Sinfdan tashqari ta'rif
#include
using namespace std;
class MyClass {
public:
void myMethod() {
cout << "Hello World!";
}
};
int main() {
MyClass myObj;
myObj.myMethod();
return 0;
}
Hello World!
Sinf tashqarida funksiyani aniqlash uchun sinf ichida e'lon qilish kerak va keyin uni sinfdan tashqarida e'lon qilish kerak. :: sinf nomini ko'rsatish uchun ishlatiladi.
#include
using namespace std;
class MyClass {
public:
void myMethod();
};
void MyClass::myMethod() {
cout << "Hello World!";
}
int main() {
MyClass myObj;
myObj.myMethod();
return 0;
}
Hello World!
|
| |