Saturday 15 March 2014

c# - How do I grab a value of an item in a List of Tuples based off of a value from another item? -


I am trying to see the value of an item in the value of the second value of the same Tupal within a list of the Tuples What I need to do after all, all Tulips have a specific item 2, choose the most recent date time from that selection and grab item 1.

For example, if I finally want to get the name most recently "from the programmer group, I argue that the argument for catching all items called" programmer "is expected, see Which is the most recent date and since 6/25 "STAN" output is more than 6/20.

  list & lt; tubal & lt; string, string, DateTime: MyList; myList.Add (NewType & lt; string; String; DateTime; ("Bob", " MyList.Add (New Tupal & String, String, DateTime; ("Stain", "Programmer", 6/25/2012); myList.Add (New Tupal & lt ; String, string, date time & gt; ("horoscope", "athlete", 6/20/2013);    

This is a very simple operation with LINQ. The first step is to order the list by the date list (item 3), after that you only first () Can query on query and turn on the most recent item Note that LINQ operations are not done in place, which means that the command of itmes in myList will not be affected by this operation, it will create a new IEnumerable which is done by tuple.Item3 , after which you have to give the item first item.

  Tupal & lt; String, String, DateTime & gt; Most recent = myList.Orderby (x = & gt; x.Item3). first ();   

To add a restriction to the group, you only need to add a clause.

  Tupal & lt; String, string, datetime & gt; Most recently = myList. There (y = & gt; y.Item2 == "Programmer"). Order By (x = & gt; x.Item3). first ();   

I recommend checking the docs of the objects query operator on LINQ. Whatever I have used, it is a standard query operator and you will see them everywhere in the modern C # code base. If you think how to use standard query operators, where, order b, redo, and maybe join it and select you will become more efficient in the operation on the collection.

No comments:

Post a Comment