Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
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
5y
93.6
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
Call If-Else Condition in a Single Line
Up Next
How I Can Call Multiple Constructors By Making A Single Object
Ebook Download
View all
Regular Expressions (Regex) in C#
Read by 197 people
Download Now!
Learn
View all
Membership not found