Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. AND == where, OR == ???

AND == where, OR == ???

Scheduled Pinned Locked Moved LINQ
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    So if I write a statement like

    var results = from items in collection
    where from.SomeProperty == SomeValueDefinedEarlier
    where from.SomeOtherProperty == SomeOtherValueDefinedEarlier

    Then the 2 where statements are an AND. How can an OR be done. Bellow is not what I expect the code to be, but gives a clear idea (I think) of why and what I am wanting to do.

    var results = from items in collection
    where from.SomeProperty == SomeValueDefinedEarlier
    where from.SomeOtherProperty == SomeOtherValueDefinedEarlier
    OR
    where from.SomeProperty == SomeValueDefinedEarlier2
    where from.SomeOtherProperty == SomeOtherValueDefinedEarlier2

    Thank you,

    0 1 Reply Last reply
    0
    • L Lost User

      So if I write a statement like

      var results = from items in collection
      where from.SomeProperty == SomeValueDefinedEarlier
      where from.SomeOtherProperty == SomeOtherValueDefinedEarlier

      Then the 2 where statements are an AND. How can an OR be done. Bellow is not what I expect the code to be, but gives a clear idea (I think) of why and what I am wanting to do.

      var results = from items in collection
      where from.SomeProperty == SomeValueDefinedEarlier
      where from.SomeOtherProperty == SomeOtherValueDefinedEarlier
      OR
      where from.SomeProperty == SomeValueDefinedEarlier2
      where from.SomeOtherProperty == SomeOtherValueDefinedEarlier2

      Thank you,

      0 Offline
      0 Offline
      0x3c0
      wrote on last edited by
      #2

      You can use boolean operators, like the && operator instead of the two 'where' clauses, and the | operator for an OR operation. For example, your first example would be:

      var results = from items in collection
      where from.SomeProperty == SomeValueDefinedEarlier
      && from.SomeOtherProperty == SomeOtherValueDefinedEarlier

      Second example would be something like this:

      var results = from items in collection
      where ((from.SomeProperty == SomeValueDefinedEarlier)
      && (from.SomeOtherProperty == SomeOtherValueDefinedEarlier))
      || ((from.SomeProperty == SomeValueDefinedEarlier2)
      && (from.SomeOtherProperty == SomeOtherValueDefinedEarlier2))

      modified on Tuesday, May 26, 2009 6:25 AM

      L J 2 Replies Last reply
      0
      • 0 0x3c0

        You can use boolean operators, like the && operator instead of the two 'where' clauses, and the | operator for an OR operation. For example, your first example would be:

        var results = from items in collection
        where from.SomeProperty == SomeValueDefinedEarlier
        && from.SomeOtherProperty == SomeOtherValueDefinedEarlier

        Second example would be something like this:

        var results = from items in collection
        where ((from.SomeProperty == SomeValueDefinedEarlier)
        && (from.SomeOtherProperty == SomeOtherValueDefinedEarlier))
        || ((from.SomeProperty == SomeValueDefinedEarlier2)
        && (from.SomeOtherProperty == SomeOtherValueDefinedEarlier2))

        modified on Tuesday, May 26, 2009 6:25 AM

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Great:thumbsup: Thank you!

        1 Reply Last reply
        0
        • 0 0x3c0

          You can use boolean operators, like the && operator instead of the two 'where' clauses, and the | operator for an OR operation. For example, your first example would be:

          var results = from items in collection
          where from.SomeProperty == SomeValueDefinedEarlier
          && from.SomeOtherProperty == SomeOtherValueDefinedEarlier

          Second example would be something like this:

          var results = from items in collection
          where ((from.SomeProperty == SomeValueDefinedEarlier)
          && (from.SomeOtherProperty == SomeOtherValueDefinedEarlier))
          || ((from.SomeProperty == SomeValueDefinedEarlier2)
          && (from.SomeOtherProperty == SomeOtherValueDefinedEarlier2))

          modified on Tuesday, May 26, 2009 6:25 AM

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          a single pipe | is a bitwise or, you wanted a boolean or which is 2 pipes ||

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups