C# FAIL

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

Code: [ Select ]
using System;
class Class1
{
  static void Main()
  {
    Console.WriteLine("Hello, world!");
  }
}
  1. using System;
  2. class Class1
  3. {
  4.   static void Main()
  5.   {
  6.     Console.WriteLine("Hello, world!");
  7.   }
  8. }


Error 1 Program 'test.exe' does not contain a static 'Main' method suitable for an entry point

Anybody know what is going on here? I tried messing with public/static/void/ in front of class & main, etc... but to no avail. I'm new to C#
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Usually for an entry point you cannot use Main() inside of a class as far as I am aware. It has to be a standalone function. The program just needs to know where to start. For everything else you could use classes I believe.
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

@Bigwebmaster: C#, like Java, requires everything to be in a class. Globals aren't allowed.

@PH: Both your class and your Main() need to be public:

CSHARP Code: [ Select ]
public class Hello1
{
   public static void Main()
   {
      System.Console.WriteLine("Hello, World!");
   }
}
  1. public class Hello1
  2. {
  3.    public static void Main()
  4.    {
  5.       System.Console.WriteLine("Hello, World!");
  6.    }
  7. }
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Ahh didnt't know that. I do C/C++ occasionally, never really have gone into those others -- was just thinking it might be the same.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

I would have assumed that classes and methods with no visibility declaration would automatically be public.
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

Nah that wasn't it. I tried all combos. I ended up finally getting it to work when I restarted Visual Studio. TY all.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

I hate the problems that are solved by restarting the application. They always make me want to restart everything to fix my problems and it doesn't work very often for me. :(

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 71 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.