Autor Beitrag
Akula
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Fr 07.12.07 17:57 
Was ist an diesem Code Falsch???

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
using System;


public class Rechnen
{
    public static void Main()
    {

        int zahl1;
        int zahl2;

        zahl1 = Console.ReadLine();

        zahl2 = Console.ReadLine();

        Console.WriteLine(zahl1);
        Console.WriteLine(zahl2);



    }
}


Zuletzt bearbeitet von Akula am Fr 07.12.07 18:02, insgesamt 2-mal bearbeitet
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 07.12.07 18:01 
Hallo und :welcome:!

Zuerst einmal:
Bitte ändere den Titel dieses Threads, der lässt einen ziemlich im Dunkeln darüber, worum es hier geht.
Dann ist es immer sinnvoll, die Fehlermeldung anzugeben, welche man erhält.

Nun zu Deinem Problem:
Console.ReadLine liefert einen String zurück, den versuchst Du in eine Variable vom Typ int zu stopfen, das geht nicht. Du musst den String erst mittels Int32.Parse(deinString) umwandeln.

Sicherlich ganz nützlich für Dich könnte das Suche bei Google "GALILEO OPENBOOK C#" sein. :-)

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Akula Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Fr 07.12.07 18:04 
Muss man das immmer so machen, ob gibt es noch eine andere Lösung. Weil bei C++ war ich was anders gewöhnt.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 07.12.07 18:07 
Ich sehe keinen anderen Weg. Console.ReadLine liefert nun mal einen String, was mir auch vernünftig erscheint. Aber die Umwandlung ist ja nicht wirklich aufwändig :nixweiss:

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Akula Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Fr 07.12.07 18:16 
Ok, dann muss ich mich damit abfinden :( .
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Fr 07.12.07 20:20 
oder du schreibst dir halt eine Methode, die das ReadLine kapselt und in ein integer umwandelt (aufpassen, was ist, wenn ReadLine keine Zahl entgegennimmt, sondern Text!)

Gruß
alias5000

_________________
Programmers never die, they just GOSUB without RETURN