Code 👨‍💻 Challenge C# dasturlash tili bo'yicha
Tags: beginners, programming, dotnet, tutorial
Published: 2024-04-15 06:11:04

> Bismillahir Rohmanir Rohim


**Task1**
Quyida keltirilgan kodning sharti quyidagicha edi.

#### 1. Convert Age
Write a C# function that converts given age in years into days. 

- consider a year has 365 days
- ignore leap years

Bu dastur ajoyib sababi sizning tug'ulgan yilingizdan ayni yillgacha necha kun o'tkanini hisoblashingiz mumkin ajoyiba 😎.

 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1b9u5zozrezs2apjv5qb.png)

Hop endi code qanday ishlashi haqida qisqacha to'xtalib o'tamiz:
Dastur o'ziga butun sonlarni qabul qiladi sababi biz bu yerda **int** tiypdan foydalanildi agarda boshqa tiyplardan foydalanilsa Tiype Error yani xatolik yuzaga keladi.
Hop dasturda shartli operatordan foydalanildi sabai biz kiritgan o'zgaruvchi 0 qiymatga ega bo'lishi ham mumkin va bu holatda bizga dasturimiz 0 qiymatni consolda ifoda etadi, agarda qandaydir son kiritilsa dasturimiz bizga shu sonni 365 ga ko'paytmasini qaytaradi.



[shartli operatorlar](https://uzbekdevs.uz/darsliklar/csharp/csharp-da-shart-operatorlari-if-if-else)

**Task2**
Bu dasturimizning sharti bilan tanshib olamiz:

#### 2. Basketball Score
You are counting total score for a basketball game. In basketball, players can score _2 pointer_ shots and _3 pointer_ shots. Given the number of _2 pointers_ and _3 pointers_, you need to calculate the total score.

Bu dasturimiz ham juda qiziqarli sabibi manga yoqadigan sport turlaridan biri Basketball 🏀 haqidaligi!

Bu dasturimiz ham o'ziga 2 ta **int** tiypida qiymat qabul qiladi va twoPointers nomidan ma'lum 2 ballik qiymat kirtiladi va kirtilgan qiymatni 2 ga ko'paytiramiz. threePointers bu o'zgaruchiga esa 3 ballik qiymat qabul qiladi kirtilgan qiymatni 3 ga ko'paytiramiz va bizga ikki o'zgaruvchining umumiy yig'indini qaytarib beriladi
Kodni qisqa va chiroyli yozishimiz mumkin
twoPointers *= 2; => twoPointers = twoPointers * 2;


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu0rfi8e525wp57bncir.png)



**Task3**
Bu dasturimizning sharti bilan tanshib olamiz:
###3. Formal Name

Given the first name, last name and a boolean representing if a person is a male, write a C# function which returns the formal name in {Mr.|Mrs.} {First name} {Last name} format.

Bu dasturimiz qanday ishlashi haqida qisqacha tanishtirib o'taman.
Bu dasturimiz qanday ishlaydi:

```
public string RasmiyIsm(string ism, string familiya, bool erkakmi)
```
 bu metodning vazifasi biz qanday parametdagi tiyplar kiritishimizni belgilaydi

```
TextInfo myTI = new CultureInfo("en-US",false).TextInfo;
```
Bu qatordagi kod orqali biz har qanday string tiypidagi malumotlarni boshqarishga imkon beradi.

```
if (isMale == true){...}
else {...}
```
Shart operatori orqali biz Erkak yoki Ayol kishi ekanligini bilishimiz va natijaga ega bo'lamiz.
```
var mr = $"Mr. {firstName} {lastName}";
```
 bu yerda  -> $ yordamida string interpolyatsiya qilindi va o'zgaruvchilar kiritildi.
```
return myTI.ToTitleCase();
```
Bu metod orqali biz kiritilgan string tiypdagi harqanday ma'lumotni Titlecase ko'rinishida chop etadi.


[How to declare and use read write properties ](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-declare-and-use-read-write-properties)

Qo'shimcha ma'lumotlarni quyidagi link orqali olishingiz mumkin
[TextInfo.ToTitleCase](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.textinfo.totitlecase?view=net-8.0)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kexs91up06eiwh1t1zvy.png)








[Data type haqida qisqacha ma'lumot olishingiz mumkin](https://dev.to/jaloldcoder98/c-dasturlash-tilida-malumot-turlari-va-ularning-ustun-hamda-kamchiliklari-2n1l)