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. c#

c#

Scheduled Pinned Locked Moved C#
csharpdata-structureshelp
10 Posts 6 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.
  • U Offline
    U Offline
    User 8670216
    wrote on last edited by
    #1

    i want too write an array that contain 2000 product info the product has id and discribtion and number of unit the number of unit should be changeable thank u all for your help :)

    V P OriginalGriffO G A 5 Replies Last reply
    0
    • U User 8670216

      i want too write an array that contain 2000 product info the product has id and discribtion and number of unit the number of unit should be changeable thank u all for your help :)

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      That's very nice, now what is the problem exaxtly? What did you try already? See here[^] on how to ask questions in this forum.

      V.

      1 Reply Last reply
      0
      • U User 8670216

        i want too write an array that contain 2000 product info the product has id and discribtion and number of unit the number of unit should be changeable thank u all for your help :)

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I suspect you want to define a class to hold info on a product and then use a List (not an array) of that class.

        1 Reply Last reply
        0
        • U User 8670216

          i want too write an array that contain 2000 product info the product has id and discribtion and number of unit the number of unit should be changeable thank u all for your help :)

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          This has a big smell of homework about it, so I won't give you code! Create a class (called Product) which has public properties Id, Description and Count The first two properties may not require a public set method, just a get so you should make these private or protected, but the final one will require both as public. You could use a backing field, or allow it to be automatic. It would be a good idea to provide a constructor which takes three parameters and sets the appropriate properties. You can then create an array of the class which has sufficient elements or (preferably) a List which meaans that you do not have to worry about the number of elements at any point. To declare an array of any class:

          MyClass[] myArrayOfClass = new MyClass[2000];

          To declare it as a List:

          List<MyClass> myListOfClass = new List<MyClass>();

          Neither of these allocate any actual instances of the class itself - just the structures that will store them. In both cases, you will have to allocate each instance with the new keyword, and add it into the appropriate structure.

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          V 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            This has a big smell of homework about it, so I won't give you code! Create a class (called Product) which has public properties Id, Description and Count The first two properties may not require a public set method, just a get so you should make these private or protected, but the final one will require both as public. You could use a backing field, or allow it to be automatic. It would be a good idea to provide a constructor which takes three parameters and sets the appropriate properties. You can then create an array of the class which has sufficient elements or (preferably) a List which meaans that you do not have to worry about the number of elements at any point. To declare an array of any class:

            MyClass[] myArrayOfClass = new MyClass[2000];

            To declare it as a List:

            List<MyClass> myListOfClass = new List<MyClass>();

            Neither of these allocate any actual instances of the class itself - just the structures that will store them. In both cases, you will have to allocate each instance with the new keyword, and add it into the appropriate structure.

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            V Offline
            V Offline
            V 0
            wrote on last edited by
            #5

            OriginalGriff wrote:

            This has a big smell of homework about it, so I won't give you code!

            Would you give code if it was not homework? Why would homework be different than work? As long as they tried and searched themselves I find a homework question as valid as a work question. :confused:

            V.

            OriginalGriffO P 2 Replies Last reply
            0
            • V V 0

              OriginalGriff wrote:

              This has a big smell of homework about it, so I won't give you code!

              Would you give code if it was not homework? Why would homework be different than work? As long as they tried and searched themselves I find a homework question as valid as a work question. :confused:

              V.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              Yes - and I do. I will even give code if it is homework and they have made a show of trying to do it and failed. But when it is clearly homework and they haven't done anything at all, no - I will give a fair amount of help (as I think I did here) but the only way they will learn it properly is to do it themselves. Just giving them the code doesn't help them to learn, and gives the teacher the wrong idea about how well his students are picking up the course. Otherwise, they could just get us to do all the homework, qualify by learning nothing, and then get a job working beside you, or me. I don't want that, and I don't think many people do.

              Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              V 1 Reply Last reply
              0
              • V V 0

                OriginalGriff wrote:

                This has a big smell of homework about it, so I won't give you code!

                Would you give code if it was not homework? Why would homework be different than work? As long as they tried and searched themselves I find a homework question as valid as a work question. :confused:

                V.

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                V. wrote:

                I find a homework question as valid as a work question

                I don't, but that doesn't matter here, this question is concerned with very basic concepts that even a hobbyist should already know.

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  Yes - and I do. I will even give code if it is homework and they have made a show of trying to do it and failed. But when it is clearly homework and they haven't done anything at all, no - I will give a fair amount of help (as I think I did here) but the only way they will learn it properly is to do it themselves. Just giving them the code doesn't help them to learn, and gives the teacher the wrong idea about how well his students are picking up the course. Otherwise, they could just get us to do all the homework, qualify by learning nothing, and then get a job working beside you, or me. I don't want that, and I don't think many people do.

                  Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                  V Offline
                  V Offline
                  V 0
                  wrote on last edited by
                  #8

                  100% agree :thumbsup:

                  V.

                  1 Reply Last reply
                  0
                  • U User 8670216

                    i want too write an array that contain 2000 product info the product has id and discribtion and number of unit the number of unit should be changeable thank u all for your help :)

                    G Offline
                    G Offline
                    GParkings
                    wrote on last edited by
                    #9

                    if(question == QuestionType.Homework)
                    {
                    knowledgeGained = DoItYourself();
                    }
                    else
                    {
                    you.ProvidedMoreInfo += (sender, args) => { us.ProvideInsightOn(question); }
                    }

                    Pedis ex oris Quidquid latine dictum sit, altum sonatur

                    1 Reply Last reply
                    0
                    • U User 8670216

                      i want too write an array that contain 2000 product info the product has id and discribtion and number of unit the number of unit should be changeable thank u all for your help :)

                      A Offline
                      A Offline
                      Abhinav S
                      wrote on last edited by
                      #10

                      You can use a collection like a List or a Dictionary .

                      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