Fisch
Mitglied
Hallo zusammen. Mal wieder eine Frage. Folgender Code stammt aus dem Buch C# lernen:
using System;
public class Addition
{
public int Addiere(int a, int b)
{
return a+b;
}
public int Addiere(int a, int b, int c)
{
return a+b+c;
}
public int Addiere(int a, int b, int c, int d)
{
return a+b+c+d;
}
}
public class Beispiel
{
public static void Main()
{
Addition myAdd = new Addition();
int a = Console.ReadLine().ToInt32(); <-----
int b = Console.ReadLine().ToInt32(); <-----
int c = Console.ReadLine().ToInt32(); <-----
int d = Console.ReadLine().ToInt32(); <-----
Console.WriteLine("a+b = {0}",myAdd.Addiere(a,b));
Console.WriteLine("a+b+c = {0}",myAdd.Addiere(a,b,c));
Console.WriteLine("a+b+c+d = {0}",myAdd.Addiere(a,b,c,d));
}
}
Für die Zeilen int a= ........ToInt32(); wird mir beim Compilieren der Fehler gemeldet 'string' enthält keine Definition für 'ToInt32'
Ist das jetzt im Buch(und auf der CD)falsch oder woran liegts??
Wenn es woanders dran liegt, woher sollte der Compiler Wissen das die Methode ToInt32()in der Klasse Convert liegt (oder sollte ich solche Fragen nicht stellen, bevor ich das Buch zu Ende gelesen habe)??
Bin für Erklärungen sehr dankbar.
Gruss
Fisch
using System;
public class Addition
{
public int Addiere(int a, int b)
{
return a+b;
}
public int Addiere(int a, int b, int c)
{
return a+b+c;
}
public int Addiere(int a, int b, int c, int d)
{
return a+b+c+d;
}
}
public class Beispiel
{
public static void Main()
{
Addition myAdd = new Addition();
int a = Console.ReadLine().ToInt32(); <-----
int b = Console.ReadLine().ToInt32(); <-----
int c = Console.ReadLine().ToInt32(); <-----
int d = Console.ReadLine().ToInt32(); <-----
Console.WriteLine("a+b = {0}",myAdd.Addiere(a,b));
Console.WriteLine("a+b+c = {0}",myAdd.Addiere(a,b,c));
Console.WriteLine("a+b+c+d = {0}",myAdd.Addiere(a,b,c,d));
}
}
Für die Zeilen int a= ........ToInt32(); wird mir beim Compilieren der Fehler gemeldet 'string' enthält keine Definition für 'ToInt32'
Ist das jetzt im Buch(und auf der CD)falsch oder woran liegts??
Wenn es woanders dran liegt, woher sollte der Compiler Wissen das die Methode ToInt32()in der Klasse Convert liegt (oder sollte ich solche Fragen nicht stellen, bevor ich das Buch zu Ende gelesen habe)??
Bin für Erklärungen sehr dankbar.
Gruss
Fisch