Statische Main Methode fehlt (C#)?

3 Antworten

Dein C#-Programm benötigt, wie es die Fehlermeldung schon sagt, eine Main-Methode. Sie dient als Einstiegspunkt. Wenn das Programm gestartet wird, startet der Programmfluss in ihr.

Du könntest deine Klasse folgendermaßen umschreiben:

// usings ...

namespace When_the_Imposter_is_SUS
{
  class Program
  {
    private static SoundPlayer player;

    public static void Main()
    {
      player = new SoundPlayer();
      player.SoundLocation = "Sound.wav";
      player.Play();
    }
  }
}

Oder du rufst deine Methode in einer Main-Methode auf.

// usings ...

namespace When_the_Imposter_is_SUS
{
  class Program
  {
    private SoundPlayer player;

    public static void Main()
    {
      var program = new Program();
      program.InitializeSound();
    }

    private void InitializeSound()
    {
      player = new SoundPlayer();
      player.SoundLocation = "Sound.wav";
      player.Play();
    }
  }
}

Indem du eine Methode hinzufügst, die diesem Gerüst entspricht:

static void Main(string[] args){
    //Code...
}