Re: What Lambda expression corresponds to this LINQ query?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raylopez99

    Re: What Lambda expression corresponds to this LINQ query?

    Thanks Dan Tallent, that worked. But I defy anybody who thinks this
    Lambda expression is more logical than the Linq/Sql equivalent.

    For example, both the below fragments yield the same thing (a
    reordering from lowest to highest valued int) but I cannot understand
    why the .orderby (r =r) works to reorder the numbers.

    RL

    //var orderLowToHigh = from m in orderHighToLow
    // orderby m ascending
    // select m;
    //Console.WriteLi ne("HightoLow") ;
    //foreach (int i in orderLowToHigh)
    //{ Console.Write(" ordrL>>H {0} ,", i); }
    ////works fine (more logical to understand than the below)


    var orderLowToHigh = orderHighToLow. OrderBy(r =>
    r).Select(r =r);
    foreach (int i in orderLowToHigh)
    { Console.Write(" L>>H {0} ", i); } //also works to reorder
    from low to high!


    Dan Tallent wrote:
    I'm not sure exactly what your trying to do but something like this will
    work
    >
    var HighesttoLowest = numbers
    >
    .OrderBy(r =r)
    >
    .Select(r =r);
  • Marc Gravell

    #2
    Re: What Lambda expression corresponds to this LINQ query?

    There are .OrderByDescend ing(...) and .ThenByDescendi ng(...) to match
    ..OrderBy(...) and .ThenBy(...)

    Marc
    [C# MVP]

    Comment

    • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

      #3
      Re: What Lambda expression corresponds to this LINQ query?

      raylopez99 wrote:
      I have a
      couple of years on-off C++ coding experience and about 2 solid months
      of C# experience, and I know about 80% of what's there to know about
      C#
      The first time around that you think that you know 80%, you know about
      20%. Keep programming for full time for a few years, and perhaps you
      will get there the second time, when you may actually be correct about
      the percentage...

      :)

      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: What Lambda expression corresponds to this LINQ query?

        raylopez99 <raylopez99@yah oo.comwrote:
        learning about dictionaries tonight...I did not realize that a
        dictionary is essentially this ordered pair, but with the ability to
        use foreach notation--
        Another misunderstandin g. A dictionary is *not* an ordered pair. It's a
        mapping. The point of a dictionary is to be able to efficiently map
        from key to value. Most implementations (such as Dictionary) do not
        preserve any particular ordering. (Those which do generally have poorer
        performance characteristics , as they have more work to do.)

        --
        Jon Skeet - <skeet@pobox.co m>
        Web site: http://www.pobox.com/~skeet
        Blog: http://www.msmvps.com/jon.skeet
        C# in Depth: http://csharpindepth.com

        Comment

        • raylopez99

          #5
          Re: What Lambda expression corresponds to this LINQ query?

          On Oct 2, 6:37 pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
          Another misunderstandin g. A dictionary is *not* an ordered pair. It's a
          mapping.
          A pedants point. Noted. I was using an ordered pair to mean
          mapping. And binary trees (ordered dictionaries) are not so bad in
          performance: a chart in Albahari et al (C# Nutshell, an excellent
          book, you should read it and review it) shows SortedDictionar y<K,V(a
          Red-Black balanced tree) is about five times slower than Dictionary,
          which is not radically slower to me (in my mind's eye).

          RL

          Comment

          • raylopez99

            #6
            Re: What Lambda expression corresponds to this LINQ query?

            On Oct 3, 1:22 pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
            >
            The results:
            SortedDictionar y`2: 56779ms
            Dictionary`2: 3585ms
            Well that's 15 times, not 5 or 6, but I still trust p. 257 of Albahari
            et al.
            >
            (I haven't replied to your other post due to its inflamatory nature, by
            the way. As I've said before: if you want sensible discussion, you
            should post sensibly and politely.)
            Well you're a smarter SOB than I thought Jon.

            Plus I had you on a Procrustean Bed--either way you answered I was
            going to skewer you, you dumb SOB.

            Thanks for your help BTW, without you, I would not be learning C# as
            effectively (nor posting here as much).

            RL

            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: What Lambda expression corresponds to this LINQ query?

              raylopez99 <raylopez99@yah oo.comwrote:
              The results:
              SortedDictionar y`2: 56779ms
              Dictionary`2: 3585ms
              >
              Well that's 15 times, not 5 or 6, but I still trust p. 257 of Albahari
              et al.
              That just gives a list of results for a single test - it doesn't
              indicate complexity. If you increase the size of the dictionary
              further, the gap would widen.

              --
              Jon Skeet - <skeet@pobox.co m>
              Web site: http://www.pobox.com/~skeet
              Blog: http://www.msmvps.com/jon.skeet
              C# in Depth: http://csharpindepth.com

              Comment

              • raylopez99

                #8
                Re: What Lambda expression corresponds to this LINQ query?

                On Oct 3, 11:27 pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
                raylopez99 <raylope...@yah oo.comwrote:
                The results:
                SortedDictionar y`2: 56779ms
                Dictionary`2: 3585ms
                >
                Well that's 15 times, not 5 or 6, but I still trust p. 257 of Albahari
                et al.
                >
                That just gives a list of results for a single test - it doesn't
                indicate complexity. If you increase the size of the dictionary
                further, the gap would widen.
                >
                --
                Jon Skeet - <sk...@pobox.co m>
                Web site:http://www.pobox.com/~skeet 
                Blog:http://www.msmvps.com/jon.skeet
                C# in Depth:http://csharpindepth.com
                OK thanks Jon! I see you wisely did not reply to my flame bait...
                might have to give up on that, you're too clever.

                RL

                Comment

                Working...