【发布时间】:2019-07-30 23:56:36
【问题描述】:
我正在做在线测试。该代码在我的 Visual Studio 2019 上运行良好,但在我提交时却不行。甚至其他在线编译器也会抛出许多编译错误。在线测试环境设置为:Mono C# 的 DMCS 版本,编译器版本 4.6.2.0,带有以下标志:-optimize+ -r:System.Numerics {files}。
我尝试将 .NET 目标框架更改为 4,但我的计算机上没有任何错误。如何将 Visual Studio 配置为与上述相同的设置?
使用系统; 使用 System.Collections.Generic;
命名空间 capgemini_kattis { 课堂节目 { 静态无效主要(字符串 [] 参数) {
/*
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Task 2
*/
bool isNumberOfCommandsRead = false;
List<string> answer = new List<string>();
string input = "????????????????????????????????";
Char[] charArray = input.ToCharArray();
int numberOfCommands = 0;
string line;
void CLEAR(int i)
{
charArray[i] = '0';
}
void SET(int i)
{
charArray[i] = '1';
}
void OR(int i, int j)
{
if (charArray[i] == '1' || charArray[j] == '1')
{
charArray[i] = '1';
}
else if (charArray[i] == '0' && charArray[j] == '0')
{
charArray[i] = '0';
}
else
{
charArray[i] = '?';
}
}
void AND(int i, int j)
{
if (charArray[i] == '1' && charArray[j] == '1')
{
charArray[i] = '1';
}
else if (charArray[i] == '0' || charArray[j] == '0')
{
charArray[i] = '0';
}
else
{
charArray[i] = '?';
}
}
while ((line = Console.ReadLine()) != null)
{
if (!isNumberOfCommandsRead)
{
numberOfCommands = Convert.ToInt32(line.Trim());
isNumberOfCommandsRead = true;
if (numberOfCommands == 0)
{
break;
}
}
else
{
string[] split = line.Split(new char[] { ' ' }, StringSplitOptions.None);
switch (split[0].Trim().ToUpper())
{
case "CLEAR":
CLEAR(Convert.ToInt32(split[1].Trim()));
numberOfCommands--;
break;
case "SET":
SET(Convert.ToInt32(split[1].Trim()));
numberOfCommands--;
break;
case "OR":
OR(Convert.ToInt32(split[1].Trim()), Convert.ToInt32(split[2].Trim()));
numberOfCommands--;
break;
case "AND":
AND(Convert.ToInt32(split[1].Trim()), Convert.ToInt32(split[2].Trim()));
numberOfCommands--;
break;
}
if (numberOfCommands == 0)
{
Array.Reverse(charArray);
string sectionResult = "";
for (int i = 0; i < (new string(charArray)).Length; i++)
{
sectionResult += charArray[i].ToString();
charArray[i] = '?';
}
answer.Add(sectionResult);
sectionResult = null;
isNumberOfCommandsRead = false;
}
}
}
foreach (string s in answer)
{
Console.WriteLine(s);
}
Console.ReadLine();
}
}
}
【问题讨论】:
-
如果您是这个意思,您可以在项目的构建设置中的某处更改语言版本。
-
@Silvermind 问题是我改变了这些但不知道如何匹配 Mono DMCS 的上述规范......
-
您可能正在使用某些 C# 8 功能而没有意识到这一点。为什么不显示一些导致问题的代码?或者因为它是单声道的,您可能正在使用一些不兼容的 Windows 库。再次,只是猜测没有代码。
-
@gilliduck 我添加了代码。也许这会有所帮助,谢谢。在我的 Windows 上安装 Mono 并尝试一下会更好吗?
标签: c# compiler-errors compilation mono