DEV Community

asilbek ibragimov
asilbek ibragimov

Posted on • Edited on

1 2 1 1 2

5.Operators

5.Operators (if , else if, else, ternary operetor, switch
Test savollari:
a) Quyidagi kodni tushuntiring:

      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

b) Ternary operatorning sintaksisi qanday? Misol keltiring.

c) Quyidagi kodda switch qismida qaysi natija chiqadi?

 int day = 3;

 switch (day) 
 {
     case 1:
         Console.WriteLine("Monday");
     break;
     case 2:
         Console.WriteLine("Tuesday");
     break;
     case 3:
         Console.WriteLine("Wedneyday");
     break;

    default:
         Console.WriteLine("Invalid day");
    break;
 }
Enter fullscreen mode Exit fullscreen mode

Test Javoblari:
a) Bu kodda x 10 ga teng. Shuning uchun if (x < 5) sharti noto'g'ri bo'ladi va bu qismi ishlamaydi.
Keyin, else if (x == 10) sharti tekshiriladi va bu to'g'ri bo'lgani uchun, "Equal to 10" deb chiqariladi.
else qismi esa ishlamidi, chunki oldingi qismi bajarildi.

b) Sintaksis: shart ? ifTrue : ifFalse

c) 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;
 }
Enter fullscreen mode Exit fullscreen mode

Kodda case 3 bo'lganda break komandasi darhol ishlaydi va Console.WriteLine bloki bajarilmaydi. Shuning uchun hech qanday natija chiqmaydi.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs