Search code examples
c#compiler-errorscompilationmono

C# code works in Visual Studio 2019 but not in online compiler


I am doing online tests. The code works perfectly at my Visual Studio 2019 but not when I submit it. Even other online compilers throw many compilation errors. The online test environment settings are: DMCS version of Mono C#, compiler version 4.6.2.0 with the flags: -optimize+ -r:System.Numerics {files}.

I tried to change .NET target framework to 4, but I don't get any errors on my computer. How can I configure Visual Studio to the same settings as above?

enter image description here

using System; using System.Collections.Generic;

namespace capgemini_kattis { class Program { static void Main(string[] args) {

        /*
        >>>>>>>>>>>>>>>>>>>>>>>>>>>>>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();
    }
}

}


Solution

  • I found that Repl.it is compiling in Mono C#, compiler version 4.6.2.0. It helped to find the issues and fix.