C# Beginner Course Exercises

Just reach the first exercises and am feeling like I am missing something. I’m struggling to understand where to even start with writing a program, and I keep getting the same error message stating I lack a static main entry point that’s usable. Reading the prompts over and over aren’t getting me anywhere - I’m wondering if I need to just re-watch the lectures up to this point or skip and circle back later, but I’m sort of getting the impression that VS has changed since this was made - I just don’t know what I don’t know.

Looking at the solutions theirs stuff in there ( like the readline bit) that hasnt even been covered… over making a program that can be interacted with in general… its all been just display outputs that he puts in

Hi,

I did not take C# course here but here is what I can tell you.

In C# you need an entry point method to start the program. By convention it is named Main and is likely part of a Program class.
Also I guess this method shall be static because in the beginning you have no instance of any class.

So traditionally the minimal code to start a C# program is

using System;

namespace MyApp{
   class Program{
      public static void Main(string[] args){
         // Put your code here
         Console.WriteLine("Hello World!");
      }
   }
}

This was prior to .NET 5 / C# 9 and it is still valid if you prefer.

Now when you start a project with Visual Studio it uses the new feature of top-level statements, global usings and file-scoped namespace. Meaning you see almost nothing in the file and you can just code.

Console.WriteLine("Hello World!");

What it is really is the content of the Main method itself so some code you would like to do just won’t work. Such as writing extra static methods into that file to use. To that purpose you need to add an extra namespace and import it.

Go in the properties of your project, Application tab and check it has a Startup object properly set.

Thank you so much for you’re quick reply, I’m out of time right now to fiddle with it, but I will definitely dig into your response and see if I can make it work later on!

Thanks again.

OK.
If you can’t make it work, please provide any error message you get to help identify your problem.

Got it! thanks a bunch… I was confused by how it switches to Program.cs - kept thinking the namespace was getting messed up. I still got a ways to go fully wrapping my head around all the terminology. Thanks for your help!