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. Class question

Class question

Scheduled Pinned Locked Moved C#
questiondata-structureshelp
5 Posts 2 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.
  • N Offline
    N Offline
    nc3b
    wrote on last edited by
    #1

    I have a dum guestion... how do i declare an array of clases, an array in wich every element is a class i tried class SomeClass { public int x; public int y; }; SomeClass[] a=new SomeClass[5]; everything goes ok. when i run the prorgam and i try smth like : a[3]=4; the program throws an exception.. pls help me..

    L 1 Reply Last reply
    0
    • N nc3b

      I have a dum guestion... how do i declare an array of clases, an array in wich every element is a class i tried class SomeClass { public int x; public int y; }; SomeClass[] a=new SomeClass[5]; everything goes ok. when i run the prorgam and i try smth like : a[3]=4; the program throws an exception.. pls help me..

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      For each class in SomeClass[] you need to do a SomeClass[i] = new SomeClass(constructor) Then you can access the values like: SomeClass[3].x = value;

      N 1 Reply Last reply
      0
      • L Lost User

        For each class in SomeClass[] you need to do a SomeClass[i] = new SomeClass(constructor) Then you can access the values like: SomeClass[3].x = value;

        N Offline
        N Offline
        nc3b
        wrote on last edited by
        #3

        Ok.. pls show me how to make such a constructor.. thx:)

        L 1 Reply Last reply
        0
        • N nc3b

          Ok.. pls show me how to make such a constructor.. thx:)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If you don't need one, then just don't declare it. A simple SomeClass[i] = new SomeClass(); will be enough then.

          N 1 Reply Last reply
          0
          • L Lost User

            If you don't need one, then just don't declare it. A simple SomeClass[i] = new SomeClass(); will be enough then.

            N Offline
            N Offline
            nc3b
            wrote on last edited by
            #5

            Hey, thx :)

            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