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. Type /Namespace error in code

Type /Namespace error in code

Scheduled Pinned Locked Moved C#
data-structuresjsonhelpquestion
6 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.
  • O Offline
    O Offline
    onetreeup
    wrote on last edited by
    #1

    I have code for a calculator, and continue to get an error that I cannot seem to find. The error: The type or namespace name 'ArrayList' could not be found(are you missing a using directive or an assembly reference) I have partial classes, delaring the following in the Calculator.Designer.cs private string m_value; private ArrayList m_store; the rest of the code below is in the Calculator class: Can someone see what might be missing? Here is the code: public partial class Calculator : Form { public Calculator() { InitializeComponent(); m_value = ""; m_store = new ArrayList(); } private void btnSeven_Click(object sender, EventArgs e) { AddToArray(btnSeven); } private void btnEight_Click(object sender, EventArgs e) { AddToArray(btnEight); } private void btnNine_Click(object sender, EventArgs e) { AddToArray(btnNine); } private void btnFour_Click(object sender, EventArgs e) { AddToArray(btnFour); } private void btnFive_Click(object sender, EventArgs e) { AddToArray(btnFive); } private void btnSix_Click(object sender, EventArgs e) { AddToArray(btnSix); } private void btnOne_Click(object sender, EventArgs e) { AddToArray(btnOne); } private void btnTwo_Click(object sender, EventArgs e) { AddToArray(btnTwo); } private void btnThree_Click(object sender, EventArgs e) { AddToArray(btnThree); } private void btnZero_Click(object sender, EventArgs e) { AddToArray(btnZero); } //create method for array to calculate private void AddToArray(Button btn) { //m_value this to set the value m_value += btn.Text; //set label lblResult = " to display it to user lblResult.Text += btn.Text; //make all enabled to use it SetEnableOperatorBtns(true); } private void btnAdd_Click(object sender, EventArgs e) { AddOperatorToArray(btnAdd); } private void btnSubtract_Click(object sender, EventArgs e) { AddOperatorToArray(btnSubtract);

    S L 2 Replies Last reply
    0
    • O onetreeup

      I have code for a calculator, and continue to get an error that I cannot seem to find. The error: The type or namespace name 'ArrayList' could not be found(are you missing a using directive or an assembly reference) I have partial classes, delaring the following in the Calculator.Designer.cs private string m_value; private ArrayList m_store; the rest of the code below is in the Calculator class: Can someone see what might be missing? Here is the code: public partial class Calculator : Form { public Calculator() { InitializeComponent(); m_value = ""; m_store = new ArrayList(); } private void btnSeven_Click(object sender, EventArgs e) { AddToArray(btnSeven); } private void btnEight_Click(object sender, EventArgs e) { AddToArray(btnEight); } private void btnNine_Click(object sender, EventArgs e) { AddToArray(btnNine); } private void btnFour_Click(object sender, EventArgs e) { AddToArray(btnFour); } private void btnFive_Click(object sender, EventArgs e) { AddToArray(btnFive); } private void btnSix_Click(object sender, EventArgs e) { AddToArray(btnSix); } private void btnOne_Click(object sender, EventArgs e) { AddToArray(btnOne); } private void btnTwo_Click(object sender, EventArgs e) { AddToArray(btnTwo); } private void btnThree_Click(object sender, EventArgs e) { AddToArray(btnThree); } private void btnZero_Click(object sender, EventArgs e) { AddToArray(btnZero); } //create method for array to calculate private void AddToArray(Button btn) { //m_value this to set the value m_value += btn.Text; //set label lblResult = " to display it to user lblResult.Text += btn.Text; //make all enabled to use it SetEnableOperatorBtns(true); } private void btnAdd_Click(object sender, EventArgs e) { AddOperatorToArray(btnAdd); } private void btnSubtract_Click(object sender, EventArgs e) { AddOperatorToArray(btnSubtract);

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      You forgot to include using System.Collections?

      Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

      O 1 Reply Last reply
      0
      • O onetreeup

        I have code for a calculator, and continue to get an error that I cannot seem to find. The error: The type or namespace name 'ArrayList' could not be found(are you missing a using directive or an assembly reference) I have partial classes, delaring the following in the Calculator.Designer.cs private string m_value; private ArrayList m_store; the rest of the code below is in the Calculator class: Can someone see what might be missing? Here is the code: public partial class Calculator : Form { public Calculator() { InitializeComponent(); m_value = ""; m_store = new ArrayList(); } private void btnSeven_Click(object sender, EventArgs e) { AddToArray(btnSeven); } private void btnEight_Click(object sender, EventArgs e) { AddToArray(btnEight); } private void btnNine_Click(object sender, EventArgs e) { AddToArray(btnNine); } private void btnFour_Click(object sender, EventArgs e) { AddToArray(btnFour); } private void btnFive_Click(object sender, EventArgs e) { AddToArray(btnFive); } private void btnSix_Click(object sender, EventArgs e) { AddToArray(btnSix); } private void btnOne_Click(object sender, EventArgs e) { AddToArray(btnOne); } private void btnTwo_Click(object sender, EventArgs e) { AddToArray(btnTwo); } private void btnThree_Click(object sender, EventArgs e) { AddToArray(btnThree); } private void btnZero_Click(object sender, EventArgs e) { AddToArray(btnZero); } //create method for array to calculate private void AddToArray(Button btn) { //m_value this to set the value m_value += btn.Text; //set label lblResult = " to display it to user lblResult.Text += btn.Text; //make all enabled to use it SetEnableOperatorBtns(true); } private void btnAdd_Click(object sender, EventArgs e) { AddOperatorToArray(btnAdd); } private void btnSubtract_Click(object sender, EventArgs e) { AddOperatorToArray(btnSubtract);

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, some remarks: 1. the ArrayList class you probably want is located in namespace System.Collections, hence it needs a using System.Collections; statement in every file that wants to use it. This is different from using System.Collections.Generic; 2. you should no longer use ArrayList, instead use List<T> which is a generic list holding objects of type T only (your choice of T!); it is supported since .NET 2.0 The generic collections require a using System.Collections.Generic; which you get for free when using Visual Studio. 3. your ArrayList is appearing in a Calculator.Designer.cs file? I have never seen the Designer use ArrayList like that, and you should not edit designer generated code at all. Put your code in Calculator.cs file, in the constructor, the Load handler, whatever. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


        O 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, some remarks: 1. the ArrayList class you probably want is located in namespace System.Collections, hence it needs a using System.Collections; statement in every file that wants to use it. This is different from using System.Collections.Generic; 2. you should no longer use ArrayList, instead use List<T> which is a generic list holding objects of type T only (your choice of T!); it is supported since .NET 2.0 The generic collections require a using System.Collections.Generic; which you get for free when using Visual Studio. 3. your ArrayList is appearing in a Calculator.Designer.cs file? I have never seen the Designer use ArrayList like that, and you should not edit designer generated code at all. Put your code in Calculator.cs file, in the constructor, the Load handler, whatever. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


          O Offline
          O Offline
          onetreeup
          wrote on last edited by
          #4

          The only code I had in the Designer.cs file was: private string m_value; private ArrayList mstore; The rest of the code is in the is in the Calculator.cs file. So now I have made the change: private string m_value; private List; m_store; // moving the declarations to the cs. file public Calculator() { InitializeComponent(); m_value = ""; m_store = new List(); } When I remove the values above, the private calls, I get even more errors. Is using partial classes possibly causing my errors? The code was original in a publ class.

          L 1 Reply Last reply
          0
          • O onetreeup

            The only code I had in the Designer.cs file was: private string m_value; private ArrayList mstore; The rest of the code is in the is in the Calculator.cs file. So now I have made the change: private string m_value; private List; m_store; // moving the declarations to the cs. file public Calculator() { InitializeComponent(); m_value = ""; m_store = new List(); } When I remove the values above, the private calls, I get even more errors. Is using partial classes possibly causing my errors? The code was original in a publ class.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, the variable declarations that used to be inside Calculator class in Calculator.Designer.cs file need to be inside Calculator class in Calculator.cs file. And that file needs all the import statements that lead the compiler to recognize the classes you are using (such as System.Collections.Generic for generic lists). If you plan on accessing m_value and m_store from outside the Calculator class, you would need to change their attribute from private to public, or better yet provide public methods or properties. I recommend you buy and study a tutorial book on C#, that would guide you step-by-step and teach you good practices from the start. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


            1 Reply Last reply
            0
            • S S Senthil Kumar

              You forgot to include using System.Collections?

              Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

              O Offline
              O Offline
              onetreeup
              wrote on last edited by
              #6

              I already had the using System.Collections.Generic; but added the using System.Collections; The errors I am getting are that: m_value does not exist in current context m_store does not exist in current context

              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