Say I have a Point:  public class Point {     double X, Y; }   I want to get the index of the element inside List&lt;Point&gt; that satisfy a condition, for example, with the maximum Point.X value inside List&lt;Point&gt;.  How would I do that with a LINQ expression?
81401
I have an array of doubles and I want the index of the highest value. These are the solutions that I've come up with so far but I think that there must be a more elegant solution. Ideas?  double[] score = new double[] { 12.2, 13.3, 5, 17.2, 2.2, 4.5 }; int topScoreIndex = score.Select((item, indx) =&gt; new {Item = item, Index = indx}).OrderByDescending(x =&gt; x.Item).Select(x =&gt; x.Index).First();  topScoreIndex = score.Select((item, indx) =&gt; new {Item = item, Index = indx}).OrderBy(x =&gt; x.Item).Select(x =&gt; x.Index).Last();  double maxVal = score.Max(); topScoreIndex = score.Select((item, indx) =&gt; new {Item = item, Index = indx}).Where(x =&gt; x.Item == maxVal).Select(x =&gt; x.Index).Single();
90864
I very rarely meet any other programmers!  My thought when I first saw the token was "implies that" since that's what it would read it as in a mathematical proof but that clearly isn't its sense.  So how do I say or read "=>" as in:-  IEnumerable&lt;Person&gt; Adults = people.Where(p =&gt; p.Age &gt; 16)   Or is there even an agreed way of saying it?
51825
I have the name of the "sort by property" in a string. I will need to use Lambda/Linq to sort the list of objects.  Ex:  public class Employee {   public string FirstName {set; get;}   public string LastName {set; get;}   public DateTime DOB {set; get;} }   public void Sort(ref List&lt;Employee&gt; list, string sortBy, string sortDirection) {   //Example data:   //sortBy = "FirstName"   //sortDirection = "ASC" or "DESC"    if (sortBy == "FirstName")   {     list = list.OrderBy(x =&gt; x.FirstName).toList();       }  }    Instead of using a bunch of ifs to check the fieldname (sortBy), is there a cleaner way of doing the sorting Is sort aware of datatype?
50228
I have a Linq to objects statement   var confirm = from l in lines.Lines   where (l.LineNumber == startline.LineNumber) || (l.LineNumber == endline.LineNumber)   select l;   The confirm object is returning an 'Object Null or Not A Reference' at at System.Linq.Enumerable.WhereListIterator`1.MoveNext()  If the result of the query was empty, it would just return an empty enumerator. I know for a fact that there are no null objects in the statement. Is it possible to step through the LINQ statement to see where it is falling over?  EDIT When I said I know for a fact that there are no null objects it turns out I was lying :[, but the question remains, though I am asuming the answer will be 'you can't really'  LINQPad is a good idea, I used it to teach myself LINQ, but I may start looking at it again as a debug / slash and burn style tool
13419
I'd like something like  int minIndex = list.FindMin(delegate (MyClass a, MyClass b) {returns a.CompareTo(b);});   Is there a builtin way to do this in .NET?
29934
I'm sure there's a nice way to do this in Python, but I'm pretty new to the language, so forgive me if this is an easy one!  I have a list, and I'd like to pick out certain values from that list. The values I want to pick out are the ones whose indexes in the list are specified in another list.  For example:  indexes = [2, 4, 5] main_list = [0, 1, 9, 3, 2, 6, 1, 9, 8]   the output would be:  [9, 2, 6]   (i.e., the elements with indexes 2, 4 and 5 from main_list).  I have a feeling this should be doable using something like list comprehensions, but I can't figure it out (in particular, I can't figure out how to access the index of an item when using a list comprehension).
104904
I really should be able to get this, but I'm just to the point where I think it'd be easier to ask.  In the C# function:  public static T GetValue&lt;T&gt;(String value) where T:new() {    //Magic happens here }   What's a good implementation for the magic? The idea behind this is that I have xml to parse and the desired values are often primitives (bool, int, string, etc.) and this is the perfect place to use generics... but a simple solution is eluding me at the moment.  btw, here's a sample of the xml I'd need to parse  &lt;Items&gt;     &lt;item&gt;         &lt;ItemType&gt;PIANO&lt;/ItemType&gt;         &lt;Name&gt;A Yamaha piano&lt;/Name&gt;         &lt;properties&gt;             &lt;allowUpdates&gt;false&lt;/allowUpdates&gt;             &lt;allowCopy&gt;true&lt;/allowCopy&gt;         &lt;/properties&gt;        &lt;/item&gt;     &lt;item&gt;         &lt;ItemType&gt;PIANO_BENCH&lt;/ItemType&gt;         &lt;Name&gt;A black piano bench&lt;/Name&gt;         &lt;properties&gt;             &lt;allowUpdates&gt;true&lt;/allowUpdates&gt;             &lt;allowCopy&gt;false&lt;/allowCopy&gt;             &lt;url&gt;www.yamaha.com&lt;/url&gt;         &lt;/properties&gt;     &lt;/item&gt;     &lt;item&gt;         &lt;ItemType&gt;DESK_LAMP&lt;/ItemType&gt;         &lt;Name&gt;A Verilux desk lamp&lt;/Name&gt;         &lt;properties&gt;             &lt;allowUpdates&gt;true&lt;/allowUpdates&gt;             &lt;allowCopy&gt;true&lt;/allowCopy&gt;             &lt;quantity&gt;2&lt;/quantity&gt;         &lt;/properties&gt;     &lt;/item&gt; &lt;/Items&gt;
18448
Let's say I have an Array of numbers: [2,3,3,4,2,2,5,6,7,2]  What is the best way to find the minimum or maximum value in that Array?  Right now, to get the maximum, I am looping through the Array, and resetting a variable to the value if it is greater than the existing value:  var myArray:Array /* of Number */ = [2,3,3,4,2,2,5,6,7,2];  var maxValue:Number = 0;  for each (var num:Number in myArray) {     if (num &gt; maxValue)         maxValue = num; }   This just doesn't seem like the best performing way to do this (I try to avoid loops whenever possible).
63624
I have an IEnumerable&lt;T&gt; and an IEnumerable&lt;U&gt; that I want merged into an IEnumerable&lt;KeyValuePair&lt;T,U&gt;&gt; where the indexes of the elements joined together in the KeyValuePair are the same. Note I'm not using IList, so I don't have a count or an index for the items I'm merging. How best can I accomplish this? I would prefer a LINQ answer, but anything that gets the job done in an elegant fashion would work as well.
31225
So I have a generic list, and an oldIndex and a newIndex value.  I want to move the item at oldIndex, to newIndex...as simply as possible.  Any suggestions?  Note  The item should be end up between the items at (newIndex - 1) and newIndex before it was removed.
123525
Is there a way to select a point from my map's current extent? I want to use ArcObjects to tell me if there is at least one point visible in my extent. I'd like to do this entirely in VBA, and without selecting any features or using any mouse-click events. (Selection can be done programmatically, just not manually.)  An demonstration would show that I have a point-type shapefile active and positioned at the top of my Table of Contents. I run my code which then displays a message box showing the longitude and latitude of the first point that is found within the current extent. Any point can be found and it's coordinates returned, just as long as that point is within the given extent.
86186
What is the difference between IQueryable&lt;T&gt; and IEnumerable&lt;T&gt;?    See also  that overlaps with this question.
118759
Question  I'm writing some code that needs to be able to get the values of the parameters from the method that called into the class. I know how to get all the way to the ParameterInfo[] array, but I don't know how to then get the values. Is this even possible?  If it is, I think it has something to do with using the MethodBody property from the MethodInfo object, which allows you to inspect the IL stream, including properties, but I don't know how to do it, and I haven't found applicable code on Google.  Code  // Finds calling method from class that called into this one public class SomeClass {     public static void FindMethod()     {         for (int i = 1; i &lt; frameCount; i++)         {             var frame = new StackFrame(i);             var methodInfo = frame.GetMethod();             if (methodInfo.DeclaringType != this.GetType())             {                 string methodName = frame.GetMethod().Name;                 var paramInfos = methodInfo.GetParameters();                  // Now what?? How do I get the values from the paramInfos                  break;             }             else if (i == frameCount - 1)             {                 throw new TransportException("Couldn't find method name");             }         }     } }
79598
I wonder if there is a counterpart to java.util.LinkedHashMap in .NET? (ie. the elements are (re)ordered automatically if I access an element. (boolean accessOrder) ).
2050
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index (1) in Python?
34531
Using LINQ to SQL, I have an Order class with a collection of OrderDetails.  The Order Details has a property called LineTotal which gets Qnty x ItemPrice.   I know how to do a new LINQ query of the database to find the order total, but as I already have the collection of OrderDetails from the DB, is there a simple method to return the sum of the LineTotal directly from the collection?  I'd like to add the order total as a property of my Order class. I imagine I could loop through the collection and calculate the sum with a for each Order.OrderDetail, but I'm guessing there is a better way.
118886
I am trying to retrive all items that are under  a certin folder, in a document library.  this is what i have so far  List DocumentsList = clientContext.Web.Lists.GetByTitle(list); CamlQuery camlQuery = new CamlQuery(); camlQuery = new CamlQuery(); camlQuery.ViewXml = @"&lt;View Scope='Recursive'&gt;                         &lt;Query&gt;                             &lt;Where&gt;                                 &lt;eq&gt;                                     &lt;FieldRef Name='FileDirRef'/&gt;                                     &lt;Value Type='Text'&gt;                                         /ecm/Business/Business/Projects/IDECO_P01030000                                     &lt;/Value&gt;                                 &lt;/eq&gt;                             &lt;/Where&gt;                         &lt;/Query&gt;                         &lt;RowLimit Paged='TRUE'&gt; 30 &lt;/RowLimit&gt;                     &lt;/View&gt;"; ListItemCollection listItems = DocumentsList.GetItems(camlQuery); clientContext.Load(listItems); clientContext.ExecuteQuery();   it is definately a caml query problem i am just unsure of how to fix it as yet any ideas would be helpfull