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. Instantiating an array of objects

Instantiating an array of objects

Scheduled Pinned Locked Moved C#
helpquestioncsharpdata-structures
4 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.
  • C Offline
    C Offline
    crushinghellhammer
    wrote on last edited by
    #1

    Hi, I'm facing the following problem in trying to code a DSP application in C#. I need to create an array of objects of a class "cBiquad" using its default constructor. The number of cBiquad objects is "mnNumBiquads". How do I do this? I tried the following: int mnNumBiquads = (mnOrder + 1)/2; int[] Biquad = new int[mnNumBiquads]; for (int i = 0; i < mnNumBiquads; i++) { Biquad[i] = new cBiquad(); } However, this gives me the obvious error of not being able to implicitly convert cBiquad to int. Could somebody suggest what I could do?

    N 1 Reply Last reply
    0
    • C crushinghellhammer

      Hi, I'm facing the following problem in trying to code a DSP application in C#. I need to create an array of objects of a class "cBiquad" using its default constructor. The number of cBiquad objects is "mnNumBiquads". How do I do this? I tried the following: int mnNumBiquads = (mnOrder + 1)/2; int[] Biquad = new int[mnNumBiquads]; for (int i = 0; i < mnNumBiquads; i++) { Biquad[i] = new cBiquad(); } However, this gives me the obvious error of not being able to implicitly convert cBiquad to int. Could somebody suggest what I could do?

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      crushinghellhammer wrote: Could somebody suggest what I could do?

      int size = 10;
      cBiquad\[\] cba = new cBiquad\[size\];
      for(int i = 0; i < size; i++)
      	cba\[i\] = new cBiquad();
      

      - Nick Parker
      My Blog | My Articles

      C 1 Reply Last reply
      0
      • N Nick Parker

        crushinghellhammer wrote: Could somebody suggest what I could do?

        int size = 10;
        cBiquad\[\] cba = new cBiquad\[size\];
        for(int i = 0; i < size; i++)
        	cba\[i\] = new cBiquad();
        

        - Nick Parker
        My Blog | My Articles

        C Offline
        C Offline
        crushinghellhammer
        wrote on last edited by
        #3

        Thanks, Nick. I *just* figured out myself, as well. cBiquad[] arrBiquads = new cBiquad[mnNumBiquads]; for (int i = 0; i < mnNumBiquads; i++) { arrBiquads[i] = new cBiquad(); } Is there a more elegant way of doing this, as in instantiating the array in just one line, using the default cBiquad constructor. I mean: cBiquad[] arrBiquads = something...

        N 1 Reply Last reply
        0
        • C crushinghellhammer

          Thanks, Nick. I *just* figured out myself, as well. cBiquad[] arrBiquads = new cBiquad[mnNumBiquads]; for (int i = 0; i < mnNumBiquads; i++) { arrBiquads[i] = new cBiquad(); } Is there a more elegant way of doing this, as in instantiating the array in just one line, using the default cBiquad constructor. I mean: cBiquad[] arrBiquads = something...

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          crushinghellhammer wrote: Is there a more elegant way of doing this Nope, that's about it. You could write a class factory of sorts that would take care of this for you, depending on what you are doing that may be overhead. - Nick Parker
          My Blog | My Articles

          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