我是D语言新手的C#程序员.我在D编程语言中有点与OOP混淆.
假设我有以下课程:
public class A {
protected void foo() {
writefln("A.foo() called.");
}
};
public class B : A {
public override void foo() {
writefln("B.foo() called.");
}
};
Run Code Online (Sandbox Code Playgroud)
该protected修改意味着我可以访问该.foo()方法只是在继承的类,所以为什么这个d程序正常编译?
这相当于C#.NET:
using System;
public class A {
protected virtual void foo() {
Console.WriteLine("a.foo() called.");
}
};
public class B : A {
public override void foo() {
Console.WriteLine("b.foo() called.");
}
};
public class MainClass {
public static void Main(string[] args) {
A …Run Code Online (Sandbox Code Playgroud) 我需要async从Form1构造函数中调用一个方法.由于构造函数不能有返回类型,我无法添加async void.我读到静态构造函数可以async但我需要从构造函数中调用不是的方法static,例如InitializeComponent()(因为它是Form的构造函数).
这堂课是:
public partial class Form1 : Form
{
InitializeComponent();
//some stuff
await myMethod();
}
Run Code Online (Sandbox Code Playgroud)
我也读了这个,但我仍然不知道如何实现这个(在我的情况下),因为该方法仍然需要使用async.
以下在主机中的行为有所不同:
echo 'DIR:' .__DIR__; // DIR:__DIR__
Run Code Online (Sandbox Code Playgroud)
localhost :(工作正常):
DIR:C:\Program Files\VertrigoServ\www
Run Code Online (Sandbox Code Playgroud)
为什么这种不同的输出
我开始使用Gtk +,我正在按照本教程如何制作第一个应用程序,但是当我尝试运行可执行文件时,我收到此错误:
Gtk-Critical **: gtk_widget_show assertion GTK_IS_WIDGET(WIDGET)
Run Code Online (Sandbox Code Playgroud)
我可以在谷歌上看到很多人有相同的错误,但我看不到如何解决这个问题的答复..
我的C代码:
#include <stdlib.h>
#include <gtk/gtk.h>
GtkBuilder *builder;
GtkWidget *app;
G_MODULE_EXPORT
void on_app_destroy (void)
{
gtk_main_quit ();
}
G_MODULE_EXPORT
void on_menu_quit_activate (void)
{
gtk_main_quit ();
exit(EXIT_SUCCESS);
}
int main (int argc, char *argv[])
{
/* Initialize GTK+ */
g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
gtk_init (&argc, &argv);
g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "tut.glade", NULL);
app = GTK_WIDGET (gtk_builder_get_object (builder, "app"));
gtk_builder_connect_signals (builder, NULL);
g_object_unref (G_OBJECT (builder));
/* …Run Code Online (Sandbox Code Playgroud) 是否有相当于WPF中winForms的.Lines?
我目前正在使用这个:
var textRange = new TextRange(TextInput.Document.ContentStart, TextInput.Document.ContentEnd);
string[] lines = textRange.Text.Split('\n');
Run Code Online (Sandbox Code Playgroud) 相当于main(int argc, char*argv[])C.例如:./foo.lua -a -b我如何阅读-a和-b从foo.lua程序中读取?
这是可能的?我需要获得Adobe Reader的完整路径,包括可执行文件名.我正在寻找Windows注册表,我做的越接近找到没有可执行文件名的完整路径.提前致谢.
我的代码:
var adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe").OpenSubKey("Acrobat Reader");
var version = adobe.GetSubKeyNames().First();
var path = adobe.OpenSubKey(version).OpenSubKey("installer").GetValue("path");
Run Code Online (Sandbox Code Playgroud)
提前致谢.
例如:
define.cs
#define FOO
Run Code Online (Sandbox Code Playgroud)
Form1.cs的
#if FOO
MessageBox.Show("foo is set!");
#else
MessageBox.Show("foo is not set!");
#endif
Run Code Online (Sandbox Code Playgroud)
在define.cs被包括在同一谟认为Form1.cs的,但上述条件得出:foo is not!
在CI可以做到
void foo() {
static int c = 0;
printf("%d,", c);
c ++;
}
foo();
foo();
foo();
foo();
Run Code Online (Sandbox Code Playgroud)
它应该打印 0,1,2,3
C#中有等价物吗?
这是有可能得到在编译时枚举成员的值?
事实上,我希望能够做到这样的事情:
enum {
FOO_FIRST = -1,
FOO_A,
FOO_B,
FOO_C,
FOO_LAST
};
#if FOO_LAST > 10
//...
#else
//..
#endif
Run Code Online (Sandbox Code Playgroud)
我知道cpp不知道变量,错误的语法等; 只有以#(右)开头的东西?但是枚举的成员具有固定大小,并且不能像10(常数整数)值那样进行更改,并且编译器知道其大小和值.所以,没有任何可能做这样的比较(如上所述)?gcc-extensions也非常受欢迎.
它只是尝试不使用#defines 重写我的所有枚举,并且不花时间做一些宏更改.