473,465 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to return the opposite value of bool?

Tee
Hi,

In VB, we have something called "not" ...
MessageBox.Show(not object.Visible) will return true if it's false and vice
versa.

is there any way we can do the same in c# ?
I tried to use !, but it doesn't work ...
Anyone can help?

Thanks,
Tee
Nov 16 '05 #1
5 12249
'!' really should do it.

bool b = true;
Console.WriteLine(! b);

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Tee" <th*@streamyx.com> wrote in message
news:um****************@TK2MSFTNGP11.phx.gbl...
Hi,

In VB, we have something called "not" ...
MessageBox.Show(not object.Visible) will return true if it's false and
vice
versa.

is there any way we can do the same in c# ?
I tried to use !, but it doesn't work ...
Anyone can help?

Thanks,
Tee

Nov 16 '05 #2
One way would be:

(boolVariable == false)

Arild

"Tee" <th*@streamyx.com> wrote in message
news:um****************@TK2MSFTNGP11.phx.gbl...
Hi,

In VB, we have something called "not" ...
MessageBox.Show(not object.Visible) will return true if it's false and
vice
versa.

is there any way we can do the same in c# ?
I tried to use !, but it doesn't work ...
Anyone can help?

Thanks,
Tee

Nov 16 '05 #3
Tee <th*@streamyx.com> wrote:
In VB, we have something called "not" ...
MessageBox.Show(not object.Visible) will return true if it's false and vice
versa.

is there any way we can do the same in c# ?
I tried to use !, but it doesn't work ...


It should work, although you'll need to convert the bool to a string,
of course. ! is definitely the operator you're after.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Hi,

Try
MessageBox.Show( (!object.Visible).ToString() );

It should work fine

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tee" <th*@streamyx.com> wrote in message
news:um****************@TK2MSFTNGP11.phx.gbl...
Hi,

In VB, we have something called "not" ...
MessageBox.Show(not object.Visible) will return true if it's false and vice versa.

is there any way we can do the same in c# ?
I tried to use !, but it doesn't work ...
Anyone can help?

Thanks,
Tee

Nov 16 '05 #5
Tee
Thank you all for the reply.
I got it to work, previously just don't know why it won't work.

Thanks

"Tee" <th*@streamyx.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...
Hi,

In VB, we have something called "not" ...
MessageBox.Show(not object.Visible) will return true if it's false and vice versa.

is there any way we can do the same in c# ?
I tried to use !, but it doesn't work ...
Anyone can help?

Thanks,
Tee

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
5
by: Edward Diener | last post by:
I am gathering from the documentation that return values from __events are not illegal but are frowned upon in .NET. If this is the case, does one pass back values from an event handler via...
4
by: AssanKhan Ismail | last post by:
Im using an C#'s user defined private function on which i want to return more than one value (like int and string ) and from that function. please let me know in advance.. assankhan Ismail
3
by: Doug | last post by:
Hi i have a method that returns a value public bool readxml (string xmlFilename, out string value) but I would like to catch an exception if it occurs in the method . How do i catch the...
16
by: DaTurk | last post by:
Hi, I have a c# application that needs to access c++ libraries, so it does this by using a managed layer of c++ CLI. Anyway, in the CLI function call, that calls the unmanaged function it...
13
by: cppquester | last post by:
A colleague told me that there is a rule about good stype that a function in C++ should have only one point of return (ie. return statement). Otherwise there might be trouble. I never heard about...
6
by: exander77 | last post by:
I am quite new to c++, about half of a year. I juct wonder, why such code is not possible: int chlen(char * ar) { for(int i=0;ar||return i;i++); } In my opinion, it would be much "cuter"...
1
by: RobRasti | last post by:
I'm trying to return a class that implements the IList interface and has a few other data members as well. // User Node class public class User { private string m_username = ""; private...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.