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. Managed C++/CLI
  4. Can I use FOR EACH on an array of structures?

Can I use FOR EACH on an array of structures?

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++visual-studiodata-structuresquestion
4 Posts 4 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.
  • B Offline
    B Offline
    BuckBrown
    wrote on last edited by
    #1

    Hi, I'm using Visual Studio 2005 C++/CLI. I would like to access an array of structures using the for each construct. Is this possible? Buck

    M L L 3 Replies Last reply
    0
    • B BuckBrown

      Hi, I'm using Visual Studio 2005 C++/CLI. I would like to access an array of structures using the for each construct. Is this possible? Buck

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      ref struct TestStruct
      {
      int i;
      };

      array<teststruct^> ^teststructarray = gcnew array<teststruct^>(20);

      for (int i = 0; i < 20; i++)
      teststructarray[i] = gcnew TestStruct();

      for each (TestStruct ^teststruct in teststructarray)
      {
      teststruct->i = 42;
      }

      value struct TestValStruct
      {
      int i;
      };

      array<testvalstruct> ^testvalstructarray = gcnew array<testvalstruct>(20);
      for each (TestValStruct %testvalstruct in testvalstructarray)
      {
      testvalstruct.i = 42;
      }

      That's better :)

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      modified on Tuesday, July 1, 2008 8:08 PM

      1 Reply Last reply
      0
      • B BuckBrown

        Hi, I'm using Visual Studio 2005 C++/CLI. I would like to access an array of structures using the for each construct. Is this possible? Buck

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        BuckBrown wrote:

        Is this possible?

        Yes. Try it! :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        1 Reply Last reply
        0
        • B BuckBrown

          Hi, I'm using Visual Studio 2005 C++/CLI. I would like to access an array of structures using the for each construct. Is this possible? Buck

          L Offline
          L Offline
          leonigah
          wrote on last edited by
          #4

          for each(myStruct in myStructArray) { //code segments }

          Nigah M Manzoor

          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