Windows Develop Bookmark and Share   
 index > Windows Forms General > Linq Where and
 

Linq Where and

I am needing to create a subset of a list<> and am doing it with Linq.


I initially made the subset list with one restrictor, and that worked fine.

var ListPatternSubset = from EnumPattern in ListPatterns
    where (EnumPattern.Length1 == EnumPiece.Length)
    select EnumPattern;//Create a subset for this piece length


but now I realize I need to narrow the subset not only be length but also by waste  



var ListPatternSubset = from EnumPattern in ListPatterns
    where (EnumPattern.Length1 == EnumPiece.Length AndAlso EnumPattern.WastePer1 > 0)                         
select EnumPattern;//Create a subset for this piece length

I have tried using "and",  "&&", "AndAlso", but nothing seems to work.
JimGuyer  Tuesday, October 06, 2009 9:47 PM
It is &&.  Document the compile error you get.
Hans Passant.
  • Marked As Answer byJimGuyer Wednesday, October 07, 2009 1:52 PM
  •  
nobugz  Tuesday, October 06, 2009 10:13 PM
It is &&.  Document the compile error you get.
Hans Passant.
  • Marked As Answer byJimGuyer Wednesday, October 07, 2009 1:52 PM
  •  
nobugz  Tuesday, October 06, 2009 10:13 PM
&& is the correct syntax.  If that didn't work I presume your issue has to do with data types (namely EnumPattern.WastePer1 not being numeric?).
syntaxeater  Tuesday, October 06, 2009 10:15 PM
Yep, that worked fine. I don't know what I did wrong the first time with '&&' I couldn't duplicate the error, but anyhow, it is working fine now.


var ListPatternSubset = from EnumPattern in ListPatterns
where (EnumPattern.Length1 == EnumPiece.Length && EnumPattern.WastePer1 > 0)

select EnumPattern;//Create a subset for this piece length


JimGuyer  Wednesday, October 07, 2009 1:50 PM

You can use google to search for other answers

Custom Search

More Threads

• Update Text fields from backgroundWorker
• repositioning toolStrips within a toolStripPanel and floating/docking
• "Error creating windows handle" and resize event
• how to use mask edit control for date????????
• forms' linkage
• Re: modal form will not close
• How To: apply a style sheet against a Document in WebBrowser
• Data extraction from online websites
• Automatic Indentation
• Displaying label along with form.