Pattern Matching | Uzbek | C#

Bugun biza C# dasturlash tilidagi legenda xususiyatlardan biri bo’lmish Pattern Matchinglarni ko’rib o’tamiz!

Bu postni ham ma’lum bir sabablarga ko’ra savol javob orqali yoritib boraman.

1 savol – Pattern Matching nima ?

_C# dasturlash tilida Pa…


This content originally appeared on DEV Community and was authored by Ozodbek

Bugun biza C# dasturlash tilidagi legenda xususiyatlardan biri bo'lmish Pattern Matchinglarni ko'rib o'tamiz!

Bu postni ham ma'lum bir sabablarga ko'ra savol javob orqali yoritib boraman.

1 savol - Pattern Matching nima ?

_C# dasturlash tilida Pattern Matching - bu kod ichida turli ma'lumot turlarini aniqlash va ular ustida ishlash ustida turli xil amallar bajarish uchun ishlatiladi. C# dasturlash tilida bu xususiyat odatda swtich case, if else operatorlari yordamida ishlatiladi. _

2 savol: Pattern Matching C# da qachon paydo bo'lgan ?

Pattern Matching C# dasturlash tilida ilk bor C# 7.0 versionda paydo bo'lgan. Undan keyin esa C# (8.0, 9.0, 10.0, 11.0, 12.0 ∞) larda ancha kengaytilishni boshlagan, hozirgacha C# kuchayishdan to'xtamayapdi 🔥

3 savol: Pattern Matching yordamida turli ma'lumot turlarini qanday qilib tekshiramiz ?

_Pattern Matching orqali ma'lumot turlarini tekshirib olish uchun is kalit so'zidan foydalaniladi. _

Misol uchun:

object obj = "Ozodbek";
if (obj is string)
    Console.WriteLine(true);
else 
    Console.WriteLine(false);

_ushbu kodda is yordamida biz "Ozodbek"ni string ekanligini aniqlashimiz mumkin. Hozir bu yerda natija true qaytadi. Sababini tushuntirib o'tirmayman. _

4 savol: Switch case da Patterns qanday ishlaydi ?

Switch case orqali C# 7.0 dan beri ishlab kelmoqda, biz esa hozirgi kundagi holatini ko'rib o'tamiz 👇

object obj = 17;
switch (obj)
{
    case int i: Console.WriteLine("Butun son. Ya'ni integer"); break;
    case double d: Console.WriteLine("O'nlik. Ya'ni double"); break;
    case string s: Console.WriteLine("String matn. Ya'ni harf, son aralash belgilar"); break;
    default: Console.WriteLine("Boshqa tip"); break;
}

Bu yerda qaysi tipga mas'ul ekanini korishimiz mumkin bo'ladi.

*5 savol: * Tuple Pattern nima va u qanday ishlaydi ?

_Tuple Pattern yordamida bir nechta qiymatlarni tekshirishimiz mumkin. Ming marta nazariya o'qigandan bir mart ko'rib review qilgan yaxshi deganlaridek👇 _

Console.WriteLine("Sonlarni birma bir kiriting! Har bir sonni kiritgandan keyin enter tugmasini bosishni unutmang! Ogohlik Tashkent talabi!");
(int, int) raqam = (int.Parse(Console.ReadLine() ?? ":)"), int.Parse(Console.ReadLine() ?? ":)"));
switch (raqam)
{
    case (0, 0): Console.WriteLine("Xato son kiritdingiz!"); break; 
    case (23, 17): Console.WriteLine("Xato son kiritdingiz, Lekin sal yaqinlashtingiz!"); break;  
    case (17, 23): Console.WriteLine("Tog'ri son kiritdingiz!"); break;
    default: Console.WriteLine("Boshqa son kiritdingiz!"); break;
}

6 savol: Property Pattern nima ?

Property pattern yordamida obyektning xususiyatlarini tekshirishimiz mumkin!

public class Circle 
{
     public int Radius { get; set; } 
}
var shakl = new Circle { Radius = 5 };
if (shakl is Circle { Radius: 5 })
{
    Console.WriteLine("Bu doirani radiusi 5 ga teng!");
}

Bu yerda property pattern yordamida shaklning Radiusi aniqlanadi

Davomi bor

https://chatgpt.com/share/12ee29aa-2b10-41e9-b577-540e6b35620a


This content originally appeared on DEV Community and was authored by Ozodbek


Print Share Comment Cite Upload Translate Updates
APA

Ozodbek | Sciencx (2024-06-26T13:29:03+00:00) Pattern Matching | Uzbek | C#. Retrieved from https://www.scien.cx/2024/06/26/pattern-matching-uzbek-c/

MLA
" » Pattern Matching | Uzbek | C#." Ozodbek | Sciencx - Wednesday June 26, 2024, https://www.scien.cx/2024/06/26/pattern-matching-uzbek-c/
HARVARD
Ozodbek | Sciencx Wednesday June 26, 2024 » Pattern Matching | Uzbek | C#., viewed ,<https://www.scien.cx/2024/06/26/pattern-matching-uzbek-c/>
VANCOUVER
Ozodbek | Sciencx - » Pattern Matching | Uzbek | C#. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/26/pattern-matching-uzbek-c/
CHICAGO
" » Pattern Matching | Uzbek | C#." Ozodbek | Sciencx - Accessed . https://www.scien.cx/2024/06/26/pattern-matching-uzbek-c/
IEEE
" » Pattern Matching | Uzbek | C#." Ozodbek | Sciencx [Online]. Available: https://www.scien.cx/2024/06/26/pattern-matching-uzbek-c/. [Accessed: ]
rf:citation
» Pattern Matching | Uzbek | C# | Ozodbek | Sciencx | https://www.scien.cx/2024/06/26/pattern-matching-uzbek-c/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.