我写了如下代码:
using System;
class Program {
static int n, m;
static int[]? f = null;
static int find(int x) {
if (f![x] == x) return x;
return f[x] = find(f[x]);
}
static void merge(int x, int y) {
x = find(x);
y = find(y);
if (x != y) f![x] = y;
}
static void Main(String[] args) {
}
}
f 在定义时是 null,在 Main 中分配 f = new int[n + 1];。
但是这段代码在 洛谷IDE 中的C# mono中无法编译通过。
报错如下
/tmp/compiler_hlxsun_w/src(16,17): error CS1519: Unexpected symbol `?' in class, struct, or interface member declaration
/tmp/compiler_hlxsun_w/src(16,21): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration
/tmp/compiler_hlxsun_w/src(19,13): error CS1525: Unexpected symbol `!'
/tmp/compiler_hlxsun_w/src(19,14): error CS1525: Unexpected symbol `['
/tmp/compiler_hlxsun_w/src(26,21): error CS1525: Unexpected symbol `!'
/tmp/compiler_hlxsun_w/src(26,22): warning CS0642: Possible mistaken empty statement
/tmp/compiler_hlxsun_w/src(26,22): error CS1525: Unexpected symbol `['
Compilation failed: 6 error(s), 1 warnings
我查阅了一些资料也没有什么发现,想请问有没有C# mono的相关资料?或者这部分应该如何写在visual studio 的C
#和C# mono中都没有warning和error?
