Hashtable problem in VisualStudio 08 C#
-
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 -
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 pleaseFrom 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 likevoid 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.
-
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 likevoid 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.
-
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.
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.
-
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.
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 ?
-
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 ?
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.”