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. Problem accessing array of objects

Problem accessing array of objects

Scheduled Pinned Locked Moved C#
helpdata-structuresquestion
3 Posts 3 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

    The problem I'm facing is as follows: I have two classes: cBiquad and cFilter. The cBiquad class has five properties that have get/set capabilities. In the cFilter constructor, I have defined an array of cBiquad objects as follows: cBiquad[] arrBiquads = null; for ( i = 0; i < mnBiquads; i++ ) { arrBiquads[i] = new cBiquad(); } Now in one of the methods in the cFilter class - SetParameters(), no arguments - I need to set the five properties of the cBiquad objects. However, when I attempt to do the following: for ( i = 0; i < mnBiquads; i++ ) { arrBiquads[i].Property1 = Prop1Value; //etc } I receive the following error message: The name 'arrBiquads' does not exist in the class or namespace 'DSP.cFilter' What should I do to get around this?

    M S 2 Replies Last reply
    0
    • C crushinghellhammer

      The problem I'm facing is as follows: I have two classes: cBiquad and cFilter. The cBiquad class has five properties that have get/set capabilities. In the cFilter constructor, I have defined an array of cBiquad objects as follows: cBiquad[] arrBiquads = null; for ( i = 0; i < mnBiquads; i++ ) { arrBiquads[i] = new cBiquad(); } Now in one of the methods in the cFilter class - SetParameters(), no arguments - I need to set the five properties of the cBiquad objects. However, when I attempt to do the following: for ( i = 0; i < mnBiquads; i++ ) { arrBiquads[i].Property1 = Prop1Value; //etc } I receive the following error message: The name 'arrBiquads' does not exist in the class or namespace 'DSP.cFilter' What should I do to get around this?

      M Offline
      M Offline
      misterbear
      wrote on last edited by
      #2

      put this statement cBiquad[] arrBiquads = null; outside of the constructor, instead of inside it. If it's inside the constructor it will only be visible to code also in constructor. public cFilter() { arrBiQuads = new cBiQuad[mnBiquads]; for ( i = 0; i < mnBiquads; i++ ) arrBiquads[i] = new cBiquad(); } Hope it works better now..

      1 Reply Last reply
      0
      • C crushinghellhammer

        The problem I'm facing is as follows: I have two classes: cBiquad and cFilter. The cBiquad class has five properties that have get/set capabilities. In the cFilter constructor, I have defined an array of cBiquad objects as follows: cBiquad[] arrBiquads = null; for ( i = 0; i < mnBiquads; i++ ) { arrBiquads[i] = new cBiquad(); } Now in one of the methods in the cFilter class - SetParameters(), no arguments - I need to set the five properties of the cBiquad objects. However, when I attempt to do the following: for ( i = 0; i < mnBiquads; i++ ) { arrBiquads[i].Property1 = Prop1Value; //etc } I receive the following error message: The name 'arrBiquads' does not exist in the class or namespace 'DSP.cFilter' What should I do to get around this?

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        If you define the array of cBiquad objects in the constructor it's only a local variable and no longer accessible as soon as the constructor scope is left. You have to define a class variable for the array. You will also have to initialize your array before you create it's members.

        cBiquad[] arrBiquads = new cBiquad[mnBiquads];
        for ( i = 0; i < mnBiquads; i++ )
        {
        arrBiquads[i] = new cBiquad();
        }


        www.troschuetz.de

        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