By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,997 Members | 1,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,997 IT Pros & Developers. It's quick & easy.

How to reverse boolean value

P: n/a
I'm new to c# and want to know the preferred way to reverse a Boolean value.
for example:

in vb I can do this:

dim flag as Boolean

flag=not flag

Is there something similar in c# or do I need to use and if statement?

Thanks.
--
mo*******@noemail.noemail
Feb 2 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

bool b = false;

b = !b;

exclamation mark
"moondaddy" <mo*******@noemail.noemailwrote in message
news:Ov**************@TK2MSFTNGP02.phx.gbl...
I'm new to c# and want to know the preferred way to reverse a Boolean
value.
for example:

in vb I can do this:

dim flag as Boolean

flag=not flag

Is there something similar in c# or do I need to use and if statement?

Thanks.
--
mo*******@noemail.noemail


Feb 2 '07 #2

P: n/a
"moondaddy" <mo*******@noemail.noemailwrote in message
news:Ov**************@TK2MSFTNGP02.phx.gbl...
I'm new to c# and want to know the preferred way to reverse a Boolean
value. for example:

in vb I can do this:

dim flag as Boolean
flag=not flag
in C# (and other C like languges) ! means not
simply replace not with ! (and add a semicolon)

flag = !flag;

Hope this helps
Bill
Feb 2 '07 #3

P: n/a
Thanks to both of you. That's exactly what i was looking for.

"Bill Butler" <qw****@asdf.comwrote in message
news:gLNwh.322$h75.252@trnddc01...
"moondaddy" <mo*******@noemail.noemailwrote in message
news:Ov**************@TK2MSFTNGP02.phx.gbl...
>I'm new to c# and want to know the preferred way to reverse a Boolean
value. for example:

in vb I can do this:

dim flag as Boolean
flag=not flag

in C# (and other C like languges) ! means not
simply replace not with ! (and add a semicolon)

flag = !flag;

Hope this helps
Bill

Feb 3 '07 #4

P: n/a
flag!=flag;

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

moondaddy wrote:
I'm new to c# and want to know the preferred way to reverse a Boolean value.
for example:

in vb I can do this:

dim flag as Boolean

flag=not flag

Is there something similar in c# or do I need to use and if statement?

Thanks.

Feb 3 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.