C# Equivalent of VB 'Not' Keyword? 
Author Message
 C# Equivalent of VB 'Not' Keyword?

In VB, I could set a boolean variable to the opposite of another boolean
variable, like this:

    Dim IsOK as Boolean
    IsOK = Not SomeBooleanFunction(MyParam)

Is there a simple way to do the same thing in C#? In other words, is there a
C# equivalent of the 'Not' keyword in VB? Right now, I'm having to do this:

    bool theResult = SomeBooleanFunction(MyParam);
    bool isOK = (theResult == false);

Not bad, but it doesn't seem quite as elegant as the old VB method.

Thanks!

___________________________
Dave Veeneman
Chicago USA



Sun, 04 Jul 2004 07:51:56 GMT  
 C# Equivalent of VB 'Not' Keyword?
try

book isOK = !SomeBooleanFunction (MyParam);

Shan


Quote:
> In VB, I could set a boolean variable to the opposite of another boolean
> variable, like this:

>     Dim IsOK as Boolean
>     IsOK = Not SomeBooleanFunction(MyParam)

> Is there a simple way to do the same thing in C#? In other words, is there
a
> C# equivalent of the 'Not' keyword in VB? Right now, I'm having to do
this:

>     bool theResult = SomeBooleanFunction(MyParam);
>     bool isOK = (theResult == false);

> Not bad, but it doesn't seem quite as elegant as the old VB method.

> Thanks!

> ___________________________
> Dave Veeneman
> Chicago USA




Sun, 04 Jul 2004 07:55:33 GMT  
 C# Equivalent of VB 'Not' Keyword?
!


Sun, 04 Jul 2004 07:56:07 GMT  
 C# Equivalent of VB 'Not' Keyword?
Another operator you'll be wanting is the "^" (EOR). This operator is
especially usefull for toggling an individual bit.

Don't confuse it with the exponentiation operator you are used to in scripting
languages and VB. (Use Math.Pow() for exponentiation while using C#.)

<air code. minor modifications may be needed>
[Flags]
public enum Foobars{
   int Zero,
   int One,
   int Two = 2,
   int Four = 4

Quote:
}

Foobars myFoobars = Foobars.One | Foobars.Four;
Console.WriteLine(myFoobars); //This ROCKS!
Console.WriteLine((int)myFoobars);
Console.WriteLine(Convert.ToString((int)MyFoobars, 2));

//toggle the 2 bit w/out changing any of the others.
myFoobars ^= Foobars.Two;
Console.WriteLine(myFoobars);
Console.WriteLine((int)myFoobars);
Console.WriteLine(Convert.ToString((int)MyFoobars, 2));

//toggle it  back
myFoobars ^= Foobars.Two;
Console.WriteLine(myFoobars);
Console.WriteLine((int)myFoobars);
Console.WriteLine(Convert.ToString((int)MyFoobars, 2));

Keep Smilin'
Ed Stegman
P.S. You could do away with the need for a NOT op by renaming your bool <g>
IsNotOk = SomeBooleanFunction(MyParam);


Quote:
> In VB, I could set a boolean variable to the opposite of another boolean
> variable, like this:

>     Dim IsOK as Boolean
>     IsOK = Not SomeBooleanFunction(MyParam)

> Is there a simple way to do the same thing in C#? In other words, is there a
> C# equivalent of the 'Not' keyword in VB? Right now, I'm having to do this:

>     bool theResult = SomeBooleanFunction(MyParam);
>     bool isOK = (theResult == false);

> Not bad, but it doesn't seem quite as elegant as the old VB method.

> Thanks!

> ___________________________
> Dave Veeneman
> Chicago USA




Sun, 04 Jul 2004 12:29:45 GMT  
 C# Equivalent of VB 'Not' Keyword?
Thanks to all! (Does that mean thanks to all, not??)

I had tried "bool theResult != SomeBooleanFunction(MyParam);" and gotten an
error.



Sun, 04 Jul 2004 19:35:32 GMT  
 C# Equivalent of VB 'Not' Keyword?



Quote:
> Thanks to all! (Does that mean thanks to all, not??)

> I had tried "bool theResult != SomeBooleanFunction(MyParam);" and gotten
an
> error.

As you know, ! means "not". So read != as "not equal".
What you want is
 bool theResult = !SomeBooleanFunction(MyParam);

Peter



Sun, 04 Jul 2004 19:55:59 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. C# equivalents to Java's volatile and transient keywords

2. C# Equivalent of VB's Alias?

3. Equivalent of VB's CHR function in C#

4. C# equivalent of VB's Space function

5. C# equivalent to VB's InputBox() ?

6. C# equivalent of using VB's WithEvents

7. VB 'TypeName' function equivalent in eVC

8. MC++ equivalent 'is' (like C#)

9. Match wildcard strings (like VB's LIKE keyword)

10. Match wildcard strings (like VB's LIKE keyword)

11. Equivalent of VB.NET's WithEvents

12. Equivalent to VB ASP's OnStartPage/OnEndPage

 

 
Powered by phpBB® Forum Software