Split() problem in Mono

Asked

Viewed 177 times

1

I’m using a platform that has multiple exercises, the Uri Online Judge, and it automatically fixes the output of the program, but it’s in Mono

This is my code:

        string a = Console.ReadLine();

        string[] temp = a.Split(" ");

        List<double> maior = new List<double>();
        maior.Add(double.Parse(temp[0]));
        maior.Add(double.Parse(temp[1]));
        maior.Add(double.Parse(temp[2]));
        maior.Sort();

        Console.WriteLine(maior[2]+ " eh o maior"); 

On my PC I use the . NET Core, and it works without error, however when I run on the platform system of this error:

Main.cs(10,31): error CS1502: The best overloaded method match for `string.Split(params char[])' has some invalid arguments
/usr/lib/mono/4.5/mscorlib.dll (Location of the symbol related to previous error)
Main.cs(10,37): error CS1503: Argument `#1' cannot convert `string' expression to type `char[]'

Link of the website with the exercise.

Mono of the site is in version: 5.4.0

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

5

In fact, finally there’s a new overload of the method Split() no. NET Core. Finally! That’s why I always recommend it. There is no . NET Standard, and why it is not in Mono or . NET Framework. Use what exists.

using static System.Console;
using System.Collections.Generic;

class Program {
    static void Main() {
        string[] temp = ReadLine().Split(new char[] { ' ' });
        var maior = new List<double> {
            double.TryParse(temp[0], out var valido) ? valido : 0,
            double.TryParse(temp[1], out valido) ? valido : 0,
            double.TryParse(temp[2], out valido) ? valido : 0
        };
        maior.Sort();
        WriteLine($" {maior[2]} eh o maior"); 
    }
}

Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.

I fixed other code problems. One of the things that are bad about these sites is that they don’t evaluate if the code is good and the person can believe that they are doing something wonderful when in fact they are just giving the expected result. There are still other problems and I would avoid the Sort(), prefer something else, like the Max(), which would even eliminate the variable.

Funcionar é diferente de estar certo - Fiat 147 caindo aos pedações circulando pelas ruas

  • Jeez, vlw worked out here, I know the code was kind of bad, to getting C#

  • @Ygorkayan see the best way to say thank you on [tour]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.