943,473 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 84961
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 16th, 2003
0

If-Else in C#

Expand Post »
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?
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,645 posts
since Feb 2002
Nov 17th, 2003
-1

Re: If-Else in C#

C# Syntax (Toggle Plain Text)
  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. }
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Nov 17th, 2003
0

Re: If-Else in C#

Thanks, Tek. I fixed the problem. I was out of scope for what I wanted to do.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,645 posts
since Feb 2002
Nov 18th, 2003
0

Re: If-Else in C#

Here is a pretty good reference Dani

C# Corner
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Feb 3rd, 2004
0

Re: If-Else in C#

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?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
CodeMasterFlex is offline Offline
16 posts
since Feb 2004
Mar 23rd, 2004
0

Re: If-Else in C#

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)
Reputation Points: 12
Solved Threads: 2
Newbie Poster
Steu is offline Offline
11 posts
since Mar 2004
Sep 1st, 2004
0

Re: If-Else in C#

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#
{
}
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Decency is offline Offline
22 posts
since Aug 2004
Sep 1st, 2004
0

Re: If-Else in C#

All the C++ would be doing is converting 1 into "true"; that's not rocket science. This would work:

while(Convert.ToBoolean(1)) {}
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Sep 1st, 2004
0

Re: If-Else in C#

i didnt say it won't work i was just trying to explain and idea.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Decency is offline Offline
22 posts
since Aug 2004
Sep 6th, 2004
0

Re: If-Else in C#

It looks to me like you were trying to make a statement and were proven wrong
Reputation Points: 46
Solved Threads: 2
Junior Poster
Iron_Cross is offline Offline
117 posts
since Jul 2003

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Enabling Step Into (#c)
Next Thread in C# Forum Timeline: ADO.Net SQL UPDATE using OleDBAdapter





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC