The Temple of Fu

code, systems and games

Single line if statement C#

leave a comment »

Who doesn’t like doing more in one line of code!

Here is a standard if else statement in C# .

if (Age == 36)
{
isMyAge = true;
}
else
{
isMyAge = false;
}

Here is the same as a single line.

isMyAge = (Age == 36) ? true : false;

Now obviously this is not a great example because the same code above could be shortened to

isMyAge = (Age == 36);

But you get the point šŸ™‚

Advertisements

Written by lordfu

September 17, 2010 at 2:49 pm

Posted in ASP.Net, C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: