Erste App
-
Mein erstes Prog (in C#) und gleich ein Fehler den ich nicht verstehe. Ich wollte eine erweitertes HelloWorld schreiben:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FirstConsoleApp { public class HelloWorldProgram { HelloWorldProgram() { this.Text = "Hello world!"; } public string Text { get;set; } public void output() { System.Console.WriteLine(Text); } static void Main(string[] args) { HelloWorldProgram hwp = new HelloWorldProgram(); hwp.output(); hwp.Text = "Hello dich selbst."; hwp.output(); System.Console.ReadKey(); } } }
Soweit klappte das, dann wollte ich es erweitern um
namespace FirstConsoleApp { public class HelloWorldProgram { /* the same */ } public class Test { static void Main(string[] args) { HelloWorldProgram hwp = new HelloWorldProgram(); // hier wollze ich GetText()/SetText()/output() verwenden } } }
Und erhalte dabei aber nun:
Error 1 'FirstConsoleApp.HelloWorldProgram.HelloWorldProgram()' is inaccessible due to its protection level
Kann mir jemand das erklären, ich dachte es ist public? Odetr passt das mit 2 mains nicht?
-
Zwei mains sind immer ungut
-
Der eigentlich Fehler ist hiermit behoben:
public HelloWorldProgram()
(alternativ auch 'internal')