If-Else in C#

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2002
Posts: 12,043
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

If-Else in C#

 
0
  #1
Nov 16th, 2003
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?
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: If-Else in C#

 
0
  #2
Nov 17th, 2003
  1. if("a"=="d")
  2. {
  3. //do something
  4. }
  5. else if("a"=="c")
  6. {
  7. // do something else
  8. }
  9. else
  10. {
  11. //do something if i am crazy
  12. }
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,043
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: If-Else in C#

 
0
  #3
Nov 17th, 2003
Thanks, Tek. I fixed the problem. I was out of scope for what I wanted to do.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: If-Else in C#

 
0
  #4
Nov 18th, 2003
Here is a pretty good reference Dani

C# Corner
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Feb 2004
Posts: 16
Reputation: CodeMasterFlex is an unknown quantity at this point 
Solved Threads: 1
CodeMasterFlex's Avatar
CodeMasterFlex CodeMasterFlex is offline Offline
Newbie Poster

Re: If-Else in C#

 
0
  #5
Feb 3rd, 2004
I know you fixed it but I recall that C# doesn't allow for boolean values like true and false I'm thinking that was it am I correct?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 11
Reputation: Steu is an unknown quantity at this point 
Solved Threads: 1
Steu Steu is offline Offline
Newbie Poster

Re: If-Else in C#

 
0
  #6
Mar 23rd, 2004
C# has the bool data type, which allows for true and false. Also another great resource for C# that I really like is http://www.codeproject.com (also has other sections besides C# too)
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 22
Reputation: Decency is an unknown quantity at this point 
Solved Threads: 1
Decency Decency is offline Offline
Newbie Poster

Re: If-Else in C#

 
0
  #7
Sep 1st, 2004
actually C# depends entirely on bool data types in both selection and loop statements, it does not accept any other types we used to in C++ for example
E.G :
While (1) // it will compile in C++ but it will be a compiler error in C#
{
}
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: If-Else in C#

 
0
  #8
Sep 1st, 2004
All the C++ would be doing is converting 1 into "true"; that's not rocket science. This would work:

while(Convert.ToBoolean(1)) {}
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 22
Reputation: Decency is an unknown quantity at this point 
Solved Threads: 1
Decency Decency is offline Offline
Newbie Poster

Re: If-Else in C#

 
0
  #9
Sep 1st, 2004
i didnt say it won't work i was just trying to explain and idea.
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 117
Reputation: Iron_Cross is an unknown quantity at this point 
Solved Threads: 2
Iron_Cross's Avatar
Iron_Cross Iron_Cross is offline Offline
Junior Poster

Re: If-Else in C#

 
0
  #10
Sep 6th, 2004
It looks to me like you were trying to make a statement and were proven wrong
elitehackers.info
Today's Penny-Arcade!
Pain is weakness leaving the body!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC