locked
Error Invalid Token "=" RRS feed

  • Question

  • no matter what i do, even if irs supposed to be there in just about every project. it states "=" is an invalid token in visual c# express

    here is the exact error message

    Invalid Token "="  in class, struct, or interface member declaration

    here is an example code that requires "=" inside the class:

    class Animal

    {

          Animal fiddlesticks;

    fiddlesticks = new Animal();

     

    fiddlesticks.kindOfAnimal = "Cat";

    fiddlesticks.name = "Fiddlesticks The Cat";

    fiddlesticks.numberOfLegs = 4;

    fiddlesticks.height = 50;

    fiddlesticks.length = 80;

    fiddlesticks.color = "Black";

    fiddlesticks.hasTail = true;

    fiddlesticks.isMammal = true;

    }

     

    Thursday, July 21, 2011 9:07 PM

Answers

  • Re-read that part. If it actually says to type what you put above throw it out. Try another one.

    Start a new console application and  replace :

     

    with

    static void Main(string[] args)
        {
        }
    

    this:

     

    static void Main(string[] args)
        {
          Animal fiddlesticks;
    
          fiddlesticks = new Animal();
    
    
    
          fiddlesticks.kindOfAnimal = "Cat";
    
          fiddlesticks.name = "Fiddlesticks The Cat";
    
          fiddlesticks.numberOfLegs = 4;
    
          fiddlesticks.height = 50;
    
          fiddlesticks.length = 80;
    
          fiddlesticks.color = "Black";
    
          fiddlesticks.hasTail = true;
    
          fiddlesticks.isMammal = true;
        }
        class Animal
        {
          public string kindOfAnimal = "";
          public string name = "";
          public int numberOfLegs = 0;
          public int height = 0;
          public int length = 0;
          public string color = "";
          public bool hasTail = false;
          public bool isMammal = false;
        }
    


    • Marked as answer by sindorei9009 Thursday, July 21, 2011 10:08 PM
    Thursday, July 21, 2011 9:52 PM

All replies

  • Does it not give you a line referance?

    If you didn't put all those in a method of some sort then that's what's causing the problem. Why not post the actual code instead of some random lines?

    Thursday, July 21, 2011 9:11 PM
  • it happens with every project i try
    Thursday, July 21, 2011 9:32 PM
  • and yea it gives me line reference
    Thursday, July 21, 2011 9:33 PM
  • Posted the code that the lines are part of including the class decleration.
    Thursday, July 21, 2011 9:35 PM
  • i have no idea what a substitute to "=" is
    Thursday, July 21, 2011 9:38 PM
  • I can't help you unless you post the code.
    Thursday, July 21, 2011 9:40 PM
  • that was the code, i am a newbie and the book suggested doing that, and i got the error message

    (the book was endorsed by microsoft)


    Thursday, July 21, 2011 9:43 PM
  • Re-read that part. If it actually says to type what you put above throw it out. Try another one.

    Start a new console application and  replace :

     

    with

    static void Main(string[] args)
        {
        }
    

    this:

     

    static void Main(string[] args)
        {
          Animal fiddlesticks;
    
          fiddlesticks = new Animal();
    
    
    
          fiddlesticks.kindOfAnimal = "Cat";
    
          fiddlesticks.name = "Fiddlesticks The Cat";
    
          fiddlesticks.numberOfLegs = 4;
    
          fiddlesticks.height = 50;
    
          fiddlesticks.length = 80;
    
          fiddlesticks.color = "Black";
    
          fiddlesticks.hasTail = true;
    
          fiddlesticks.isMammal = true;
        }
        class Animal
        {
          public string kindOfAnimal = "";
          public string name = "";
          public int numberOfLegs = 0;
          public int height = 0;
          public int length = 0;
          public string color = "";
          public bool hasTail = false;
          public bool isMammal = false;
        }
    


    • Marked as answer by sindorei9009 Thursday, July 21, 2011 10:08 PM
    Thursday, July 21, 2011 9:52 PM
  • ty, your my life saver and i guess the book is a little outdated

    so as in an html webpage the class is the body and the static void main thing is the head

    Thursday, July 21, 2011 9:59 PM
  • Don't forget to mark it as the answer.
    Thursday, July 21, 2011 10:05 PM
  • the book probably did say that, i just skipped to code parts to code it. oops, not gonna skip information again
    Thursday, July 21, 2011 10:09 PM