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. Storing data in an array

Storing data in an array

Scheduled Pinned Locked Moved C#
tutorialvisual-studiocomdata-structuresxml
8 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
    Brad Wick
    wrote on last edited by
    #1

    I have been looking at http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx trying to figure this out but I just seem to get it. I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data. The only way I can think to explain it is more like XML. One function will return different items from a XML feed, and the other will return one record from an XML feed with the information Example for multiple records:

    [Message]
    [ID]44562[/ID]
    [/Message]
    [Message]
    [ID]44562[/ID]
    [/Message]
    [Message]
    [ID]44562[/ID]
    [/Message]

    Example for single records:

    [Message]
    [ID]44562[/ID]
    [From]Scott[/From]
    [To]Scott[/To]
    [Subject]Test[/Subject]
    [/Message]

    L B D 3 Replies Last reply
    0
    • B Brad Wick

      I have been looking at http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx trying to figure this out but I just seem to get it. I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data. The only way I can think to explain it is more like XML. One function will return different items from a XML feed, and the other will return one record from an XML feed with the information Example for multiple records:

      [Message]
      [ID]44562[/ID]
      [/Message]
      [Message]
      [ID]44562[/ID]
      [/Message]
      [Message]
      [ID]44562[/ID]
      [/Message]

      Example for single records:

      [Message]
      [ID]44562[/ID]
      [From]Scott[/From]
      [To]Scott[/To]
      [Subject]Test[/Subject]
      [/Message]

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Brad Wick wrote:

      I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data.

      If you can't figure out how to add data to an array then I suggest you get a beginners book. Look for book reviews here on the site.

      led mike

      B 1 Reply Last reply
      0
      • L led mike

        Brad Wick wrote:

        I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data.

        If you can't figure out how to add data to an array then I suggest you get a beginners book. Look for book reviews here on the site.

        led mike

        B Offline
        B Offline
        Brad Wick
        wrote on last edited by
        #3

        Adding items to an array I can do, but not a Multidimensional Array. Some people do not read books, but search the internet and learn from each time they tackle something. I have been playing around in C# for some time and can do pretty much anything that is needed, but trying to learn some other items. Why dont you just respond to every post "go buy a book" that is so much more helpful then actually helping someone out.

        L 1 Reply Last reply
        0
        • B Brad Wick

          I have been looking at http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx trying to figure this out but I just seem to get it. I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data. The only way I can think to explain it is more like XML. One function will return different items from a XML feed, and the other will return one record from an XML feed with the information Example for multiple records:

          [Message]
          [ID]44562[/ID]
          [/Message]
          [Message]
          [ID]44562[/ID]
          [/Message]
          [Message]
          [ID]44562[/ID]
          [/Message]

          Example for single records:

          [Message]
          [ID]44562[/ID]
          [From]Scott[/From]
          [To]Scott[/To]
          [Subject]Test[/Subject]
          [/Message]

          B Offline
          B Offline
          Bert delaVega
          wrote on last edited by
          #4

          Just look at your XML examples (hierarchy). It's just a name/value pair array.

          B 1 Reply Last reply
          0
          • B Brad Wick

            Adding items to an array I can do, but not a Multidimensional Array. Some people do not read books, but search the internet and learn from each time they tackle something. I have been playing around in C# for some time and can do pretty much anything that is needed, but trying to learn some other items. Why dont you just respond to every post "go buy a book" that is so much more helpful then actually helping someone out.

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            Brad Wick wrote:

            Some people do not read books, but search the internet and learn from each time they tackle something.

            Ok, good luck.

            led mike

            1 Reply Last reply
            0
            • B Bert delaVega

              Just look at your XML examples (hierarchy). It's just a name/value pair array.

              B Offline
              B Offline
              Brad Wick
              wrote on last edited by
              #6

              So you think it would be better to store the information in XML to pass between different functions/objects?

              B 1 Reply Last reply
              0
              • B Brad Wick

                So you think it would be better to store the information in XML to pass between different functions/objects?

                B Offline
                B Offline
                Bert delaVega
                wrote on last edited by
                #7

                No. I don't know your application so it's hard to say what's better. What I was getting at was that if you're confused about multi-dimensional arrays, just look at your XML to visualize what it would look like. In 2.0 forward, you could use a generic list, but I think you said you're using 1.0+ [Edit] No, the 1.0 was from another question. Sorry.

                1 Reply Last reply
                0
                • B Brad Wick

                  I have been looking at http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx trying to figure this out but I just seem to get it. I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data. The only way I can think to explain it is more like XML. One function will return different items from a XML feed, and the other will return one record from an XML feed with the information Example for multiple records:

                  [Message]
                  [ID]44562[/ID]
                  [/Message]
                  [Message]
                  [ID]44562[/ID]
                  [/Message]
                  [Message]
                  [ID]44562[/ID]
                  [/Message]

                  Example for single records:

                  [Message]
                  [ID]44562[/ID]
                  [From]Scott[/From]
                  [To]Scott[/To]
                  [Subject]Test[/Subject]
                  [/Message]

                  D Offline
                  D Offline
                  DaveyM69
                  wrote on last edited by
                  #8

                  The way I normally handle this is to create a class (or struct if more appropriate) for a single item, then create a class that is a generic list of single items. e.g.

                  public class MyMessage
                  {
                  // variables, properties, methods, constructors etc...
                  }

                  using System.Collections.Generic;
                  public class MyMessageCollection : List<MyMessage>
                  {
                  // returns the message with specified ID or new empty message if not found
                  public MyMessage FindItemFromID(int id)
                  {
                  MyMessage found = this.Find(c => c.ID == id);
                  return found != null ? found : new MyMessage();
                  }

                  // other methods (loading, saving...) etc...
                  }

                  Dave

                  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