Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Min Max of Point Collection

Min Max of Point Collection

Scheduled Pinned Locked Moved LINQ
questioncsharplinqtutorial
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    How to I get the min max of X and/or Y in a point collection (or can't it be done using Linq)? I am assuming something with Lamdas but I am not well versed with them yet so I can see how it would be done. To retiterate in code:

    List[Point] pointCollection = GetABunchOfPoints();

    var pointWithMinXandY = ????

    var pointWithMinX = ????

    var pointWithMinY = ????

    Thank you in advance.

    ASCII stupid question, get a stupid ANSI

    L 1 Reply Last reply
    0
    • L Lost User

      How to I get the min max of X and/or Y in a point collection (or can't it be done using Linq)? I am assuming something with Lamdas but I am not well versed with them yet so I can see how it would be done. To retiterate in code:

      List[Point] pointCollection = GetABunchOfPoints();

      var pointWithMinXandY = ????

      var pointWithMinX = ????

      var pointWithMinY = ????

      Thank you in advance.

      ASCII stupid question, get a stupid ANSI

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Here is what I got for Max

      private int GetMaxX()
      {
      int maxX = 0;
      var query = (from p in pointCollection
      select new
      {
      p
      }).Max(p2 => p2.p.X);

                  return query;
          }
      

      ASCII stupid question, get a stupid ANSI

      modified on Tuesday, January 26, 2010 11:10 AM

      D 1 Reply Last reply
      0
      • L Lost User

        Here is what I got for Max

        private int GetMaxX()
        {
        int maxX = 0;
        var query = (from p in pointCollection
        select new
        {
        p
        }).Max(p2 => p2.p.X);

                    return query;
            }
        

        ASCII stupid question, get a stupid ANSI

        modified on Tuesday, January 26, 2010 11:10 AM

        D Offline
        D Offline
        Dan Mos
        wrote on last edited by
        #3

        getting the max .X and .Y:

        var maxX = points
        .Select(x => x.X).Max();

        var maxY = points
        .Select(x => x.Y).Max();

        getting the min .X and .Y:

        var minX = points
        .Select(x => x.X).Min();

        var minY = points
        .Select(x => x.Y).Min();

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups