0

I'm very new to programming, and right now I am learning how to code. Right now I am trying to create some database program, which has some kind of menu, ability to write in data, and read the data which has been already inputed. Somehow I managed to create Menu method, but I don't know, how to open in directly from method Main. Could you please help me, what to do ? I've been looking for simmilar thread, but I can't find anything helpful for me. Again, I am learning from absolute zero, so I hope you won't be very salty about it.

PS: Places where are "Hello World" section I haven't written yet. I got it there only for filing space purposes.

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp1
{
   public class Program
    {
        private void Main(string[] args)
        {

        }
        private static bool Menu()
        {
            Console.Clear();
            Console.WriteLine("Vyberte moznost:");
            Console.WriteLine("1) Zapis nóveho studenta [N]");
            Console.WriteLine("2) Seznam zapsanych studentu [S]");
            Console.WriteLine("3) Konec [K]");
            Console.Write("\r\nSelect an option: ");
            var input = Console.ReadKey();
            switch (input.Key)
            {
                case ConsoleKey.N:
                    NewStudent();
                    return true;
                case ConsoleKey.S:
                    StudentSeznam();
                    return true;
                case ConsoleKey.K:
                    return false;
                default:
                    return true;
            }
        }
        public static void NewStudent()
        {
            Console.WriteLine("Hello World.");
        }
        private static void StudentSeznam()
        {
            Console.WriteLine("Hello World.");
        }
    }
    public class StudentList
    {       
           Console.WriteLine("Hello World.");
    }
}
Tarik
  • 10,810
  • 2
  • 26
  • 40
  • Just write `Menu();`? – Progman Apr 26 '20 at 17:47
  • Thank you very much for quick response! I could have thought of that. But when i do type this to `Main`, it says i have error cs5001, which is error in compilation. And I cannot open the code to try it. But I don't have any .exe to open, or even to work with. – Karel Klíma Apr 26 '20 at 17:53
  • Tell us the error message – Tarik Apr 26 '20 at 18:00
  • I have Visual Studio in native language, but I believe translator did it's job.**error CS5001 The program does not contain a static Main method suitable for the entry point.** – Karel Klíma Apr 26 '20 at 18:03
  • I'm really out of my mind. I put `static` before `Main()`. Error was still displayed, but i tried to run it anyway, and it left. I am so sorry to ask such stupid questions. And I thank you so much for needed help. – Karel Klíma Apr 26 '20 at 18:14

2 Answers2

0

As previously mentiod. Just write Menu() in the main method.

But also, you have a Console.WriteLine directly in your class StudentList. This is not valid.

public class StudentList
    {       
           Console.WriteLine("Hello World.");
    }

Put it in a constructor, method or just remove it.

Here is a little info about classes https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/classes

matscr
  • 26
  • 1
  • 4
0

Your Main method must be static, otherwise the program won't start. Then you can call the Menu() method from Main():

public class Program
{
    static void Main(string[] args)
    {
        Menu();
    }
M4N
  • 94,805
  • 45
  • 217
  • 260