RSS Forums RSS
Please support our C# advertiser: Programming Forums
Views: 51875 | Replies: 11 | Solved | Thread Tools  Display Modes
Reply
Join Date: Oct 2004
Posts: 1
Reputation: muraleedharanks is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
muraleedharanks muraleedharanks is offline Offline
Newbie Poster

Re: If-Else in C#

  #11  
Oct 6th, 2004
Originally Posted by cscgal
This might sound silly. But I'm working on a C# assignment for school right now, and I can't get a simple if-else statement to work. Isn't the syntax the same as in C++ or Java?

I want to do one thing if a boolean variable is true, something else if it's not. The "bool" type exists in C#, right?

bool bFirsttime;

if (bFirsttime)
{
//code for true condition
}
else
{
//code for false condition

}
Reply With Quote  
Join Date: Oct 2004
Posts: 3
Reputation: guitarded is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
guitarded guitarded is offline Offline
Newbie Poster

Re: If-Else in C#

  #12  
Oct 18th, 2004
alternate shorthand syntax...

txtTest.Text = (txtName.Text == String.Empty) ? "No name" : txtName.Text;

which translates to...

if(txtName.Text == String.Empty)
txtTest.Text = "No name";
else
txtName.Text;

maybe not as readable, but sure saves typing!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the C# Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:33 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC