Sunday, 15 April 2012

C# how to find a value in a List collection -


I have a collection of the following classes in this list

  public class MyFile {public String filename {get; Set; } Received public int status { Set; }}  

Then the definition of the list will appear as:

  Private list & lt; MyFile & gt; MyFiles = new list & lt; MyFile & gt; ();  

I can also search using this collection:

  MyFile tmpFile = MyFiles.Find (Rep (MyFile item) {return item.FileName == fileName;});  

So far it looks good, except what I would like to do is return the mimf which not only matches the file name but also the highest value in that field position.

So if the following items are in the list:

  myDocument.doc | 1 myDocument.doc | 2 myDocument.doc | 3 myPDF.pdf | 1 myPDF.pdf | 2 myPDF.pdf | 3  

and my search method has the value of fileName = "myDocument.doc", even then mydocument.doc | 3 I am missing the argument to return this item, because it is the highest value of the position

I have to have query in SQL

  Top 1 * from MyFiles Select, where filename = 'myDocument.doc' order based on the order;  

Thanks in advance

Can you use Linux ? If so, you should do a simple query like this:

  MyFile file = MyFiles Where (f = & gt; f.FileName == fileName). Order-Byescosing (f = & gt; f.position) .FirstOrDefault ();  

No comments:

Post a Comment