C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Call C# If Else In A Single Line
WhatsApp
Pankaj Pandey
6y
94.4
k
0
5
25
Blog
Here is the syntax of using C# if else statement in a single line.
(Condition) ?
"Value For true"
:
" Value For False "
OK, here is your typical if else statement:
if
(x==1)
{
x=10;
}
else
{
x=15;
}
This is how we can replace the above code block in a single line:
x=(x==1)?10:15;
Here is a detailed tutorial,
How To Use C# If Else Statement
People also reading
Membership not found