DEV Community

umida5
umida5

Posted on

Operators

int temperature = 30;

if(temperature > 25)
{
    Console.WriteLine("Hot");
}
else if(temperature > 15)
{
    Console.WriteLine("Warm");
}
else
{
    Console.WriteLine("Cold");
}
Enter fullscreen mode Exit fullscreen mode

Natija : Hot.

b) Switch operatoridan foydalanib, quyidagi if-else kodini switch operatoriga o'zgartiring.

int day = 3;

if(day == 1)
{
    Console.WriteLine("Monday");
}
else if(day == 2)
{
    Console.WriteLine("Tuesday");
}
else if(day == 3)
{
    Console.WriteLine("Wednesday");
}
else 
{
    Console.WriteLine("Invalid day");
}
Enter fullscreen mode Exit fullscreen mode

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

c) Ternary operator yordamida quyidagi kodni qisqartiring.

int a = 10;

string result;

if(a > 5)
{
    result = "Greater than 5";
}
else
{
    result = "Less than or equal to 5";
}
Enter fullscreen mode Exit fullscreen mode

to ternary operator:

int a = 10;

string result;

result = (a > 5 ? "Greater than 5":"Less than or equal to 5");
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

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

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay