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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Hashtable problem in VisualStudio 08 C#

Hashtable problem in VisualStudio 08 C#

Scheduled Pinned Locked Moved C#
csharphelpdotnetvisual-studiocom
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.
  • M Offline
    M Offline
    msheekhah
    wrote on last edited by
    #1

    I created a project using .NET Framework 3.0 before I downloaded 3.5... using C# on Visual Studio 08 Creating a windows program, a basic forms program I have the following: using System; using System.Collections; namespace Zombie_Zombie_Zombie { partial class Form1 { protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code private void InitializeComponent() { this.tabControl1 = new System.Windows.Forms.TabControl(); ... private System.Windows.Forms.RichTextBox outputRichText; private System.Windows.Forms.LinkLabel linkLabel14; class character { protected Hashtable charSheet = new Hashtable(); protected Hashtable calcSheet = new Hashtable(); protected Hashtable mutantStats = new Hashtable(); protected Hashtable mutantPowers = new Hashtable(); // charSheet is the base character sheet with user modifiable values // calcSheet are the values after calculations... Strength plus Melee plus Sword // non user modifiable // mutantStats are the mutant powers that directly affect the base stats, and are added // into calcSheet charSheet.Add("Name","") ... charSheet.Add("Money", ""); } } } Now I'm using this because that's the syntax given here: <a href="http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx">MSDN Hashtable Class (System.Collections) I had originally tried charSheet["Name"] = ""; because I was using Beginning C# Game Programming page 105 on Hashtables. This is the error code I get: Error 1 Invalid token '(' in class, struct, or interface member declaration C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Zombie Zombie Zombie\Zombie Zombie Zombie\Form1.Designer.cs 499 26 Zombie Zombie Zombie ... Error 39 Invalid token '(' in class, struct, or interface member declaration C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Zombie Zombie Zombie\Zombie Zombie Zombie\Form1.Designer.cs 537 26 Zombie Zombie Zombie help please

    M 1 Reply Last reply
    0
    • M msheekhah

      I created a project using .NET Framework 3.0 before I downloaded 3.5... using C# on Visual Studio 08 Creating a windows program, a basic forms program I have the following: using System; using System.Collections; namespace Zombie_Zombie_Zombie { partial class Form1 { protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code private void InitializeComponent() { this.tabControl1 = new System.Windows.Forms.TabControl(); ... private System.Windows.Forms.RichTextBox outputRichText; private System.Windows.Forms.LinkLabel linkLabel14; class character { protected Hashtable charSheet = new Hashtable(); protected Hashtable calcSheet = new Hashtable(); protected Hashtable mutantStats = new Hashtable(); protected Hashtable mutantPowers = new Hashtable(); // charSheet is the base character sheet with user modifiable values // calcSheet are the values after calculations... Strength plus Melee plus Sword // non user modifiable // mutantStats are the mutant powers that directly affect the base stats, and are added // into calcSheet charSheet.Add("Name","") ... charSheet.Add("Money", ""); } } } Now I'm using this because that's the syntax given here: <a href="http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx">MSDN Hashtable Class (System.Collections) I had originally tried charSheet["Name"] = ""; because I was using Beginning C# Game Programming page 105 on Hashtables. This is the error code I get: Error 1 Invalid token '(' in class, struct, or interface member declaration C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Zombie Zombie Zombie\Zombie Zombie Zombie\Form1.Designer.cs 499 26 Zombie Zombie Zombie ... Error 39 Invalid token '(' in class, struct, or interface member declaration C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Zombie Zombie Zombie\Zombie Zombie Zombie\Form1.Designer.cs 537 26 Zombie Zombie Zombie help please

      M Offline
      M Offline
      Member 1033907
      wrote on last edited by
      #2

      From your code example, it is absolutely unclear which lines are in the class declaration and which are in the method flow (in InitializeComponent()). If you try to declare a class (character) from within a method or call a method (Hastable.Add) from within a class declaration, the compiler won't buy it. You can't do stuff like

      void SomeFunction()
      {
      class SomeClass // will throw compiler error
      {
      }
      }

      or

      class SomeClass
      {
      ht = new HashTable();
      ht.Add(...); // will throw compiler error
      }

      My kind advice is that you should learn some basic softball programming first, then move on to OOP and C# and then move on to game development. H.

      M 1 Reply Last reply
      0
      • M Member 1033907

        From your code example, it is absolutely unclear which lines are in the class declaration and which are in the method flow (in InitializeComponent()). If you try to declare a class (character) from within a method or call a method (Hastable.Add) from within a class declaration, the compiler won't buy it. You can't do stuff like

        void SomeFunction()
        {
        class SomeClass // will throw compiler error
        {
        }
        }

        or

        class SomeClass
        {
        ht = new HashTable();
        ht.Add(...); // will throw compiler error
        }

        My kind advice is that you should learn some basic softball programming first, then move on to OOP and C# and then move on to game development. H.

        M Offline
        M Offline
        msheekhah
        wrote on last edited by
        #3

        lol. I learned oop over ten years ago on C++ before the ansi iso standard and just now trying to get back into it... thanks for the help tho.

        M M 2 Replies Last reply
        0
        • M msheekhah

          lol. I learned oop over ten years ago on C++ before the ansi iso standard and just now trying to get back into it... thanks for the help tho.

          M Offline
          M Offline
          Member 1033907
          wrote on last edited by
          #4

          No offense meant:-) I just couldn't decide if you screwed up copying the code example or if you screwed up writing the code. The latter would explain the compiler errors:-) Good luck, H.

          1 Reply Last reply
          0
          • M msheekhah

            lol. I learned oop over ten years ago on C++ before the ansi iso standard and just now trying to get back into it... thanks for the help tho.

            M Offline
            M Offline
            msheekhah
            wrote on last edited by
            #5

            i had forgotten that I was trying to build it using a template of sample code I was working with... so I started again...

            using System;
            using System.Collections.Generic;
            using System.ComponentModel;
            using System.Data;
            using System.Drawing;
            using System.Linq;
            using System.Text;
            using System.Windows.Forms;

            namespace WindowsFormsApplication4
            {
            public partial class Form1 : Form
            {
            public Form1()
            {
            InitializeComponent();
            }
            }
            public class character
            {
            protected Hashtable charSheet = new Hashtable();
            protected Hashtable calcSheet = new Hashtable();
            protected Hashtable mutantStats = new Hashtable();
            protected Hashtable mutantPowers = new Hashtable();
            public character()
            {
            }
            charSheet.Add("Name","")
            ...
            charSheet.Add("Money", "");
            }
            }

            I still do not see what I'm doing. why won't it let me make a hashtable in the class character when it's apart of the namespace with System.Container ?

            H 1 Reply Last reply
            0
            • M msheekhah

              i had forgotten that I was trying to build it using a template of sample code I was working with... so I started again...

              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.Data;
              using System.Drawing;
              using System.Linq;
              using System.Text;
              using System.Windows.Forms;

              namespace WindowsFormsApplication4
              {
              public partial class Form1 : Form
              {
              public Form1()
              {
              InitializeComponent();
              }
              }
              public class character
              {
              protected Hashtable charSheet = new Hashtable();
              protected Hashtable calcSheet = new Hashtable();
              protected Hashtable mutantStats = new Hashtable();
              protected Hashtable mutantPowers = new Hashtable();
              public character()
              {
              }
              charSheet.Add("Name","")
              ...
              charSheet.Add("Money", "");
              }
              }

              I still do not see what I'm doing. why won't it let me make a hashtable in the class character when it's apart of the namespace with System.Container ?

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

              msheekhah wrote:

              charSheet.Add("Name","") ... charSheet.Add("Money", "");

              These two lines must be in a method, if you wish to avoid compiler errors. Assignments and the like cannot just be in class scope, they must be in a method. Only declarations can be just in the class scope.

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

              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