Having Issues With C# Code Compiling: It Says Unexpected Symbol

blackneos940

Active Member
Credits
31
Hey guys! :3 I'm back! :) And yes, I'm healthy, and have not fallen ill.... Though as for my mind, well.... But never mind all that. :D So I've been writing a Program in C#, and it won't Compile, with either
Bash:
mcs
or Online. :( First, the Code:

C#:
// This Program is released under the 2-Clause BSD License.
//Copyright 2020 Redacted FBI oof

// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// That's it! :) No restrictions. Just give credit. :) No, it won't blow up your PC. :)

using System;

using System.Net; // This is for remote communication. May be replaced later with a different Library.

namespace Systems_Go

{
  class Arm_Create

  {
    public static string first_arm;

    public int arm_one;

    public Arm_Create()

    {
      first_arm = "Hellfire_One";

      arm_one = 1;

    }

  }

  public Arm_Create(string _first_arm, int _arm_one)

  {
    first_arm = _first_arm;

    arm_one = _arm_one;

  }

  public void Test_Print()

  {
    Console.WriteLine("First Arm: " + first_arm);

    Console.WriteLine("Arm One Created: " + arm_one);

  }

  class Hades

  {
    static void Main()

    {
      Console.WriteLine("Test_Run_One\n");

    }

  }

}
So, if you use Mono to Compile it, it should throw these errors:

Code:
H_A_D_E_S.cs(39,9): error CS1525: Unexpected symbol `Arm_Create', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct'
H_A_D_E_S.cs(42,4): error CS1525: Unexpected symbol `first_arm', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct'
H_A_D_E_S.cs(46,3): error CS1514: Unexpected symbol `}', expecting `.' or `{'
H_A_D_E_S.cs(48,9): error CS1525: Unexpected symbol `void', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct'
Compilation failed: 4 error(s), 0 warnings
And it shows, obviously, that the Compilation failed. :( Any ideas, guys? :( Everywhere I searched Online says something about either a line or lines of Code missing a Bracket({}), a Semicolon( ;, but... It's all there. :\ Maybe my good friend @JasKinasis could shed some light on this issue.... :3 Thanks for any help, guys. :) And stay safe, and remember: stay /home :D
 


JasKinasis

Well-Known Member
Credits
1,193
Looking at that, your parameterised Arm_Create constructor and your Test_Print method are declared outside of the Arm_Create class. That is the reason for the errors.

If you look at the line before the parameterised Arm_Create constructor, you have prematurely closed the class declaration/definition with a curly right-brace }.
Move that brace to AFTER the closing brace for the Test_Print method and you should be good.... I think.
It's been a long while since I did any C# coding.

e.g.
Your current code with some additional comments:
C#:
namespace Systems_Go
{
  class Arm_Create
  {
    public static string first_arm;
    public int arm_one;

    public Arm_Create()
    {
      first_arm = "Hellfire_One";
      arm_one = 1;
    }
  } // End class  Arm_Create - ** This closing brace is in the wrong place and needs to be moved! **

// This is outside the Arm_Create class
  public Arm_Create(string _first_arm, int _arm_one)
  {
    first_arm = _first_arm;
    arm_one = _arm_one;
  }

// This is outside the Arm_Create  class
  public void Test_Print()
  {
    Console.WriteLine("First Arm: " + first_arm);
    Console.WriteLine("Arm One Created: " + arm_one);
  }
// ** move the closing brace for the class to this line instead! **

  class Hades
  {
    static void Main()
    {
      Console.WriteLine("Test_Run_One\n");
    }
  } // end class Hades
} // end namespace Systems_Go
Moving the closing brace to the specified position should hopefully fix the problem!
 
Last edited:

blackneos940

Active Member
Credits
31
Looking at that, your parameterised Arm_Create constructor and your Test_Print method are declared outside of the Arm_Create class. That is the reason for the errors.

If you look at the line before the parameterised Arm_Create constructor, you have prematurely closed the class declaration/definition with a curly right-brace }.
Move that brace to AFTER the closing brace for the Test_Print method and you should be good.... I think.
It's been a long while since I did any C# coding.

e.g.
Your current code with some additional comments:
C#:
namespace Systems_Go
{
  class Arm_Create
  {
    public static string first_arm;
    public int arm_one;

    public Arm_Create()
    {
      first_arm = "Hellfire_One";
      arm_one = 1;
    }
  } // End class  Arm_Create - ** This closing brace is in the wrong place and needs to be moved! **

// This is outside the Arm_Create class
  public Arm_Create(string _first_arm, int _arm_one)
  {
    first_arm = _first_arm;
    arm_one = _arm_one;
  }

// This is outside the Arm_Create  class
  public void Test_Print()
  {
    Console.WriteLine("First Arm: " + first_arm);
    Console.WriteLine("Arm One Created: " + arm_one);
  }
// ** move the closing brace for the class to this line instead! **

  class Hades
  {
    static void Main()
    {
      Console.WriteLine("Test_Run_One\n");
    }
  } // end class Hades
} // end namespace Systems_Go
Moving the closing brace to the specified position should hopefully fix the problem!
Thank you buddy... :3 I'll copy and paste the Code you changed into Nano or some other Text Editor, and try to Compile it. :) I will report back as soon as I can, so I can mark this as resolved for anyone else who might have this issue. :) BRB! :3
 

blackneos940

Active Member
Credits
31
@JasKinasis It works!! :3 It even Prints "Test_Run_One"!! :3 Whoo hoo!! :D I need to be more careful next time.... I'll keep a copy of that Code elsewhere and study it so I THOROUGHLY understand just how and where I went wrong.... Instead of beating myself up, I should really see this as an opportunity to learn new things about C#, and Code structure in general ! :D Have a good one buddy! :3
 

JasKinasis

Well-Known Member
Credits
1,193
As always, I’m glad to have helped.

Sometimes when you’re writing code, it’s very easy to make a simple mistake and not be able to see the problem. It's like you can’t see the forest for all of the trees.

And when that happens, and you get an error message - it’s frustrating. Especially when you can’t see the problem.

But when you are stuck - it always helps to have a fresh pair of eyes to look at the code. Either by taking a break and coming back to it fresh yourself, or by getting somebody else to look at it.

It’s been many years since I did any c# coding, but I immediately spotted that those two methods were declared outside of the class and thought that was suspicious enough.

And the error messages confirmed to me that this was indeed the problem. Sometimes the error messages for certain problems are a bit cryptic. It takes a little while to understand what they are trying to say.

The error messages here were saying that the compiler wasn’t expecting those two methods. It clearly says it was expecting a class, or a delegate, or an enum etc.
So although the error messages didn’t say it directly, they implied that those two methods were out of place.

Also, the last line the compiler thought was “good” was the line before the first error. And that was the line containing the Right curly brace }, which closed the class definition.

So all of those combined factors confirmed my initial diagnosis. That the closure of the class was in the wrong place.

Correctly interpreting/understanding what is causing a compiler error can be tricky and frustrating sometimes. Especially when the error isn't actually on one of the lines that the compiler is complaining about. On rare occasions (like this one) you have to look at the line of code before the first error, in order to see where the problem is.
 

derss

New Member
Credits
42
Also got needed help in this thread, because I am still newbie in web development and programming. I work on one startup now. It is my first experience in web developing. I have plan to create app like here It will be my first experience
 
Last edited:



Top