What good is .SELECT in LINQ anyway? seems useless compared to .where

Tech-Archive recommends: Fix windows errors by optimizing your registry



Please examine the below code. Kindly explain why .Select does not
work except to produce a 'bool' and further, how can you extract which
member is true/false?

This is the complete code (Jon).

I used .Where to get the information I need (namely, finding a maximum
point in an array of Points, then finding all points less than this
maximum point). Why could not I use .Select to do this? Select seems
useless.

RL

//Windows Forms so for points use using System.Windows.Forms; and
using.System.Linq;
/// find the maximum Point in an array of Points, then find all points
that are less than this maximum point.


Point[] PtsInArray = { new Point(10, 10), new Point(20, 1), new Point
(1,2), new Point(2,2) };

int Max = PtsInArray.Max(ImplicitDummyVar =>
ImplicitDummyVar.X + ImplicitDummyVar.Y);

int Min = PtsInArray.Min(x => x.X + x.Y);

Console.WriteLine("Here are the Max, Min: Max= {0}, Min=
{1}", Max, Min);

// IEnumerable<Point> i1 = PtsInArray.Select(x => (x.X + x.Y) >
Min); //won't compile, why?

var MinPtsArr2 = PtsInArray.Select(x => (x.X + x.Y) >
Min);
foreach (var i2 in MinPtsArr2)
{
Console.WriteLine("data is: {0}", i2);

}

IEnumerable<Point> SomePtsArr3 = PtsInArray.Where(x => (x.X
+ x.Y) < Max);
foreach (Point p in SomePtsArr3)
{
Console.WriteLine("Works, point p less than {0}, is:
{1},{2}", Max, p.X, p.Y);
}

/* //output
*
* Here are the Max, Min: Max= 21, Min= 3
data is: True
data is: True
data is: False
data is: True
Works, point p less than 21, is: 10,10
Works, point p less than 21, is: 1,2
Works, point p less than 21, is: 2,2
*
*
* */
.



Relevant Pages

  • Re: [PHP] foreach() using current() strange beahvior
    ... that's expected as foreach moves the internal array pointer, ... When using the internal pointer just by calling current(so not moving ... Unless the array is referenced, foreach operates on a copy of the ...
    (php.general)
  • Re: List sites user has access to.
    ... user is a member ... Label webServiceInfo = new Label; ... SPSiteCollection allSites = oWebApplication.Sites; ... foreach ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: Best Coding Practice
    ... I needed to add an array class member to an object. ... OO standpoint to make a FreeProduct class which extends the Product ... Cost is an attribute, and different values for attributes should not determine new products. ...
    (comp.lang.php)
  • Re: a question about for and foreach
    ... foreach (@array) { ... why @array are changed after this foreach loop!!! ... The "foreach" loop iterates over a normal list value and sets the ... If any element of LIST is an lvalue, you can modify it by modifying ...
    (perl.beginners)
  • Re: Best Coding Practice
    ... I needed to add an array class member to an object. ... the logic was the same between the two arrays aside from the price, ... and the child classes the specific elements. ...
    (comp.lang.php)