Frage

It's really ridiculous that I'm having so much trouble with something so basic, but googling and asking on another forum so far haven't helped me.

I'm new to MonoDevelop, usually use VS. So I make a gtk# 2.0 project, add a new class to the project, fill the class with stuff, and then try to initialize an instance of that class by adding it after Build(); in MainWindow.cs (similar to putting it in InitializeComponent(); in Form1.cs in VS)

    Build ();
    MyClass MyClassInstance1 = new MyClass();

I checked and stuff there does get done and I'm pretty sure that's where you're supposed to put this stuff, but with any class name I get the error, "The name `MyClass' does not exist in the current context"

So how the heck do you initialize objects when your program starts?

War es hilfreich?

Lösung

It's because MonoDevelop may have created the MyClass class in another namespace which has the same name as your solution.

So either:

  • right-click "MyClass" in your code and search for something like "resolve" (but I've found right-clicking can freeze your IDE :()
  • add a using statement at the top of your file, e.g. if your solution is named "GtkTests":

    using GtkTests
    
  • instead of MyClass use <SolutionName>.MyClass:

    GtkTests.MyClass MyClassInstance1 = new GtkTests.MyClass();
    
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top