gpt4 book ai didi

c# - 新创建的 GTK# 项目中的错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:31:55 24 4
gpt4 key购买 nike

我刚刚在 32 位机器的 Ubuntu 14.10 中安装了 Monodelopvel 5.7.0。我创建了一些用于测试的控制台 C# 应用程序,一切正常。但是当我尝试创建一个 GTK# 项目并执行它时,我在 Program 和 MainWindow 类中出现以下 3 个错误:

  • 命名空间“Application”中不存在类型或命名空间名称“Init”

  • 命名空间“Application”中不存在类型或命名空间名称“Run”

  • 命名空间“Application”中不存在类型或命名空间名称“Quit”

我一直在尝试添加一些引用资料并寻找其他解决方案,但没有成功。

这些是应用程序的类:

程序.cs

using System;
using Gtk;

namespace Application
{
class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
MainWindow win = new MainWindow ();
win.Show ();
Application.Run ();
}
}
}

主窗口.cs

using System;
using Gtk;

public partial class MainWindow: Gtk.Window
{
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
Build ();
}

protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
}

最佳答案

我刚修好了。当我错误地创建项目时,我将其命名为“02”,因此在 Program.cs 类中,默认情况下 Monodelop 将其命名为“Application"而不是项目名称,导致出现错误。

您必须更改 Program.cs 类中的命名空间“Application”:

Program.cs

using System;
using Gtk;

namespace two // for example
{
class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
MainWindow win = new MainWindow ();
win.Show ();
Application.Run ();
}
}
}

为避免这种情况,请记住不要在项目名称中仅使用数字。

关于c# - 新创建的 GTK# 项目中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29779654/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com