DEV Community

umida5
umida5

Posted on

Operators:If,else if,else,ternary operator,switch

If,else if,else

int x = 10;
if(x < 5)
{
    Console.WriteLine("Less than 5");
}
else if(x == 10)
{
    Console.WriteLine("Equal to 10");
}
else
{
   Console.WriteLine("Greater than 5");
}
Enter fullscreen mode Exit fullscreen mode

Birinchi bo'lib if ni shartini tekshiradi.x 10 ga teng,sharti false bo'lgani uchun else if shartini tekshiradi.x 10 ga teng bo'lib sharti true bo'ladi va natijada "Equal to 10".

ternary operator
1.shart yozish
2.agar shart to'g'ri bo'lsa nima natija chiqishi.
3.agar shart noto'g'ri bo'lsa nima natija chiqishi.

(condition?true:false) - sintaksisi

Example: (a < 5 ? "a 5 dan kichik":"a 5 dan katta");

Switch

int day = 3;
switch(day)
{
case 1:
Console.WriteLine("Monday");
break;
case 2:
Console.WriteLine("Tuesday");
break;
case 3:
Console.WriteLine("Wednesday");
break;
default:
Console.WriteLine("Invalid day");
break;
}

natija:"Wednesday" - chunki day 3 ga teng case 3 ga kiradi.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more