MonoDevelop C# - 编译 class 文件时出错
MonoDevelop C# - Error while compiling class file
我正在尝试在 MonoDevelop 版本 5.0.1.1 中编译一个基本测试 class。见以下代码:
using System;
using System.IO;
using System.Linq;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
namespace testproject
{
public class TestClass
{
public TestClass
{
string name;
public string Name
{
get {return name;}
set {name = value;}
}
int[] integers;
public int this[int i]
{
get {if (i < 5) {return integers[i];} else {return -1;}}
set {if (i < 5) {integers[i] = value;}}
}
public TestClass(string _name)
{
name = _name;
}
public override string ToString ()
{
string output = name + ":";
for (int i = 0; i < 5; i++)
{
if (i != 4) {output += " " + i.ToString() + ",";}
else {output += " " + i.ToString();}
}
return output;
}
}
}
}
这是我创建的一个非常基本的测试 class,用于在 Linux 上试用 MonoDevelop(我刚从 Windows 上的 VS2017 切换过来)。当我尝试编译时,出现以下错误:
/home/main/mono-cs/projects/test-project/test-
project/TestClass.cs(3,3): Error CS1519: Invalid token '{' in class,
struct, or interface member declaration (CS1519) (test-project)
和
/home/main/mono-cs/projects/test-project/test-
project/TestClass.cs(1,1): Error CS1022: Type or namespace definition,
or end-of-file expected (CS1022) (test-project)
我仔细检查了一下,所有的花括号都有正确的对应。有什么见解吗?
谢谢大家!
- 删除
public TestClass
,也就是在嵌套中重复添加TestClass
- 初始化
integers
否则你会得到一个运行时错误。(感谢@Ron Beyer 提醒)
这里
namespace testproject
{
public class TestClass
{
string name;
public string Name
{
get {return name;}
set {name = value;}
}
int[] integers;
public int this[int i]
{
get {if (i < 5) {return integers[i];} else {return -1;}}
set {if (i < 5) {integers[i] = value;}}
}
public TestClass(string _name)
{
name = _name;
integers = new int[100];
}
public override string ToString ()
{
string output = name + ":";
for (int i = 0; i < 5; i++)
{
if (i != 4) {output += " " + i.ToString() + ",";}
else {output += " " + i.ToString();}
}
return output;
}
}
}
我正在尝试在 MonoDevelop 版本 5.0.1.1 中编译一个基本测试 class。见以下代码:
using System;
using System.IO;
using System.Linq;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
namespace testproject
{
public class TestClass
{
public TestClass
{
string name;
public string Name
{
get {return name;}
set {name = value;}
}
int[] integers;
public int this[int i]
{
get {if (i < 5) {return integers[i];} else {return -1;}}
set {if (i < 5) {integers[i] = value;}}
}
public TestClass(string _name)
{
name = _name;
}
public override string ToString ()
{
string output = name + ":";
for (int i = 0; i < 5; i++)
{
if (i != 4) {output += " " + i.ToString() + ",";}
else {output += " " + i.ToString();}
}
return output;
}
}
}
}
这是我创建的一个非常基本的测试 class,用于在 Linux 上试用 MonoDevelop(我刚从 Windows 上的 VS2017 切换过来)。当我尝试编译时,出现以下错误:
/home/main/mono-cs/projects/test-project/test- project/TestClass.cs(3,3): Error CS1519: Invalid token '{' in class, struct, or interface member declaration (CS1519) (test-project)
和
/home/main/mono-cs/projects/test-project/test- project/TestClass.cs(1,1): Error CS1022: Type or namespace definition, or end-of-file expected (CS1022) (test-project)
我仔细检查了一下,所有的花括号都有正确的对应。有什么见解吗?
谢谢大家!
- 删除
public TestClass
,也就是在嵌套中重复添加TestClass
- 初始化
integers
否则你会得到一个运行时错误。(感谢@Ron Beyer 提醒)
这里
namespace testproject
{
public class TestClass
{
string name;
public string Name
{
get {return name;}
set {name = value;}
}
int[] integers;
public int this[int i]
{
get {if (i < 5) {return integers[i];} else {return -1;}}
set {if (i < 5) {integers[i] = value;}}
}
public TestClass(string _name)
{
name = _name;
integers = new int[100];
}
public override string ToString ()
{
string output = name + ":";
for (int i = 0; i < 5; i++)
{
if (i != 4) {output += " " + i.ToString() + ",";}
else {output += " " + i.ToString();}
}
return output;
}
}
}