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. C#
  4. How to acheive this in LINQ?

How to acheive this in LINQ?

Scheduled Pinned Locked Moved C#
csharpwpflinqtutorialquestion
10 Posts 5 Posters 0 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.
  • J Offline
    J Offline
    John ph
    wrote on last edited by
    #1

    List<MyStyle> styles = new List<MyStyle>();

    foreach (var item in items)
    {
    styles.Add(GetMyStyle(item.style));
    }

    - Regards -
       J O N


    A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


    G P S S 4 Replies Last reply
    0
    • J John ph

      List<MyStyle> styles = new List<MyStyle>();

      foreach (var item in items)
      {
      styles.Add(GetMyStyle(item.style));
      }

      - Regards -
         J O N


      A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


      G Offline
      G Offline
      Groulien
      wrote on last edited by
      #2

      I don't think LINQ is meant to do this. LINQ is "Language Integrated Query", a query being something of a question used to select, modify or delete data. The performance gain, if any, will be slight. I actually think it might slow it down. But if you must... (Doing this from memory)

      List<MyStyle> styles = new List<MyStyle>();
      styles.AddRange((MyStyle[])(from item in items select GetMyStyle(item.style)).ToArray());

      J 1 Reply Last reply
      0
      • J John ph

        List<MyStyle> styles = new List<MyStyle>();

        foreach (var item in items)
        {
        styles.Add(GetMyStyle(item.style));
        }

        - Regards -
           J O N


        A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Off the top of my head:

        List<MyStyle> styles = items.Select(item => GetMyStyle(item.style)).ToList();

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        G J 2 Replies Last reply
        0
        • P Pete OHanlon

          Off the top of my head:

          List<MyStyle> styles = items.Select(item => GetMyStyle(item.style)).ToList();

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          G Offline
          G Offline
          Groulien
          wrote on last edited by
          #4

          Isn't that a Lambda?

          P 1 Reply Last reply
          0
          • G Groulien

            Isn't that a Lambda?

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            It's LINQ using a Lambda expression, as a lot of LINQ does.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            1 Reply Last reply
            0
            • P Pete OHanlon

              Off the top of my head:

              List<MyStyle> styles = items.Select(item => GetMyStyle(item.style)).ToList();

              Forgive your enemies - it messes with their heads

              My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

              J Offline
              J Offline
              John ph
              wrote on last edited by
              #6

              thanks..

              - Regards -
                 J O N


              A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


              P 1 Reply Last reply
              0
              • J John ph

                thanks..

                - Regards -
                   J O N


                A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                No problem. Glad to help.

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                1 Reply Last reply
                0
                • G Groulien

                  I don't think LINQ is meant to do this. LINQ is "Language Integrated Query", a query being something of a question used to select, modify or delete data. The performance gain, if any, will be slight. I actually think it might slow it down. But if you must... (Doing this from memory)

                  List<MyStyle> styles = new List<MyStyle>();
                  styles.AddRange((MyStyle[])(from item in items select GetMyStyle(item.style)).ToArray());

                  J Offline
                  J Offline
                  John ph
                  wrote on last edited by
                  #8

                  may be you are right. i was just wondering how to do that using LINQ. anyway thanks for the reply.

                  - Regards -
                     J O N


                  A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


                  1 Reply Last reply
                  0
                  • J John ph

                    List<MyStyle> styles = new List<MyStyle>();

                    foreach (var item in items)
                    {
                    styles.Add(GetMyStyle(item.style));
                    }

                    - Regards -
                       J O N


                    A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


                    S Offline
                    S Offline
                    Sanjay J Patolia
                    wrote on last edited by
                    #9

                    I think you may use its constructor to add values in it. List<MyStyle> l = new List<MyStyle>(items.Select(s => GetMyStyle(s.style))); Thanks :)

                    1 Reply Last reply
                    0
                    • J John ph

                      List<MyStyle> styles = new List<MyStyle>();

                      foreach (var item in items)
                      {
                      styles.Add(GetMyStyle(item.style));
                      }

                      - Regards -
                         J O N


                      A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


                      S Offline
                      S Offline
                      Subin Mavunkal
                      wrote on last edited by
                      #10

                      try like this , var styles=items.Select(item=>GetMyStyle(item.Style)).ToList(); sorry...answers are already there :(

                      modified on Wednesday, May 25, 2011 9:29 AM

                      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