Operators
Asadbek-IT
Posted on October 11, 2024
int x = 10; //b degan o'zgaruvchi yaratamiz va 10-ga tenglaymiz
if(x < 5) //agar x 5-dan kichik bo'lsa, pastdagi text chiqadi
{
Console.WriteLine("Less than 5");
}
else if(x == 10) //agar x 10-ga teng bo'lsa, pastdagi text, lekn keyingi else if lar ishlamaydi
{
Console.WriteLine("Equal to 10");
}
else //agar hech qaysi shart kelmasa, pastdagi text chiqadi
{
Console.WriteLine("Greater than 5");
}
Ternary operator C# dasturlash tilida shartlarni qisqa va sodda yozish uchun ishlatiladigan maxsus operator hisoblanadi, Asosiy maqsadi oddiy if-else blokini qisqaroq shaklda ifodalashdir.
using System;
class Program
{
static void Main()
{
int age = 20;
string result = (age >= 18) ? "Voyaga yetgan" : "Voyaga yetmagan";
Console.WriteLine(result);
}
}
javob: Wenesday
Posted on October 11, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024