4 Replies - 291 Views - Last Post: 06 May 2019 - 07:22 AM Rate Topic: -----

#1 robgeek   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 15-January 13

Trying to create a program with many files and classes and failing.

Posted 05 May 2019 - 04:10 PM

Good evening!
I'm newbie in c# and I'm using Linux with mono. I'm trying to create a program with other classes in different files.
To start I tried to make a test like in the following code:
//Menu.cs
using System;

namespace Test {
	public class Menu {
		public Menu() {
			Console.WriteLine("I'm the Menu.\n");
		}
	}
}

//Program.cs
using System;

namespace Test {
	public class Program {
		public static void Main(String[] args) {
			Menu menu = new Menu();
		}
	}
}


I'm getting the follwing error message:
error CS0246: The type or namespace name `Menu' could not be found. Are you missing an assembly reference?


How can I fix this?

This post has been edited by robgeek: 05 May 2019 - 04:14 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Trying to create a program with many files and classes and failing.

#2 Sheepings   User is offline

  • D.I.C Lover
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,260
  • Joined: 05-December 13

Re: Trying to create a program with many files and classes and failing.

Posted 05 May 2019 - 04:52 PM

This is a common problem when you don't do renaming properly, renaming of namespaces classes etc or edit externally from VS.

The simple thing to check here is your program settings, and which file is set to run at startup. See my screenshot and post back once you resolve the startup file to the new namespace you likely renamed or changed. Then build again. Does it compile after selecting an alternative file?
Attached Image
Was This Post Helpful? 1
  • +
  • -

#3 robgeek   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 15-January 13

Re: Trying to create a program with many files and classes and failing.

Posted 05 May 2019 - 05:01 PM

Thanks for your answer!

The thing is I'm not using IDE. Just Sublime Text. The program I need to do is too small and simple to install some IDE.
To compile I'm using:
mcs Program.cs


To run it:
mono Program.exe


Both files are in the same folder.

This post has been edited by Skydiver: 07 May 2019 - 03:24 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 Sheepings   User is offline

  • D.I.C Lover
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,260
  • Joined: 05-December 13

Re: Trying to create a program with many files and classes and failing.

Posted 05 May 2019 - 05:11 PM

Ahh I see. You do know, regardless creating your project for Linux, you can also do that using IDE like VS? Try adding a using directive to your application name.

I think you might find this useful https://code.visualstudio.com/download - can run Linux - EDIT Or Mono Develop http://monodevelop.com/

You're going to need an IDE, and are best using one of them two editors to help the process.

This post has been edited by Sheepings: 05 May 2019 - 05:44 PM

Was This Post Helpful? 1
  • +
  • -

#5 robgeek   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 15-January 13

Re: Trying to create a program with many files and classes and failing.

Posted 06 May 2019 - 07:22 AM

I solved my problem.
I thought it was like java where in many case you just have to compile the main file and all other file are compile too, like:
javac Main.java


In this case I had to compile all other files, like in c/c++:
mcs Program.cs Rsa.cs Menu.cs
mono Program.exe


But thanks for your answer anyway.

This post has been edited by robgeek: 06 May 2019 - 07:22 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1