Results 1 to 6 of 6

Thread: problem understanding andalso

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    problem understanding andalso

    I have a statement that I am using two NOT operators.

    can this be simplified using a 'andalso'?


    VB Code:
    1. If Not rs.BOF And Not rs.EOF Then

    VB Code:
    1. If Not rs.BOF AndAlso rs.EOF Then

  2. #2
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    I think both will do.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    cool. I thought so but reading in the msdn confused me a TAD lol

    it says that if the first expression evaluates to false, the second is considered false. in my case, the evaluation would be negated with that NOT operator. I dont like using NOT but I am converting some vb6 code another developer had.

    thanks!!

  4. #4
    PowerPoster SuperSparks's Avatar
    Join Date
    May 2003
    Location
    London, England
    Posts
    265
    I don't think that the AndAlso will have any effect on the Not operator. The difference between And and AndAlso is that And will evaluate both parts of the expression even if the first part is false, whereas AndAlso will skip to the next instruction if the fist part is false. So all it does is improve performance a little bit.
    Nick.

  5. #5
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    I think C# uses AndAlso by default right?
    \m/\m/

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Originally posted by PT Exorcist
    I think C# uses AndAlso by default right?
    I would assume so... if its modeled after Java... but then again, its basically the same as using:
    VB Code:
    1. If x = True Then
    2.    If y = True  Then
    3.       'do something
    4.        z=True
    5.    End If
    6.   End If

    or
    VB Code:
    1. If (x AndAlso y) Then z=True

    Code:
    //C#
    If (x && y)
       //do something
       z=true;
    Last edited by nemaroller; Mar 31st, 2004 at 06:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width