Wie behebe ich diese ArgumentNullException in int.Parse?

Dies ist die .cs-Datei läuft gut in Mono:

using System;

public class HelloWorld
{
    static public void Main ()
    {
    Console.WriteLine("Enter a number");

    int UserNumber = int.Parse(Console.ReadLine());

    Console.WriteLine("Your number is: " + UserNumber);
    }
}

Ich habe diese Test.cs-Datei in Xamarin geöffnet, was ordnungsgemäß funktioniert hat. Dann wähle ich 'Run'> 'Start Without Debugging' und diese Fehler erscheinen im Anzeigefeld:

Enter a number

Unhandled Exception:
System.ArgumentNullException: Argument cannot be null.
Parameter name: String
  at System.Number.StringToNumber (System.String str, NumberStyles options, System.NumberBuffer& number, System.Globalization.NumberFormatInfo info, Boolean parseDecimal) [0x00054] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/number.cs:1084 
  at System.Number.ParseInt32 (System.String s, NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/number.cs:755 
  at System.Int32.Parse (System.String s) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/int32.cs:140 
  at HelloWorld.Main () [0x0000b] in /Users/Yardenbourg/Desktop/Test.cs:9 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Argument cannot be null.
Parameter name: String
  at System.Number.StringToNumber (System.String str, NumberStyles options, System.NumberBuffer& number, System.Globalization.NumberFormatInfo info, Boolean parseDecimal) [0x00054] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/number.cs:1084 
  at System.Number.ParseInt32 (System.String s, NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/number.cs:755 
  at System.Int32.Parse (System.String s) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/int32.cs:140 
  at HelloWorld.Main () [0x0000b] in /Users/Yardenbourg/Desktop/Test.cs:9 
The application was terminated by a signal: SIGHUP

Ich bin nicht sicher, was das Problem hier ist. Könnte es mit dieser Zeile zu tun haben?

int UserNumber = int.Parse(Console.ReadLine());

Antworten auf die Frage(4)

Ihre Antwort auf die Frage