wahrscheinlich etwas INCREDIBLY einfach haha, aber ich habe so viel Mühe, den Code herauszufinden, ich müsste schreiben, um die GetArea-Berechnung in eine Datei geschrieben werden, hier ist ein Teil des Codes alle Hilfe geschätzt :)Wie schreibe ich Objekte in eine Datei
using System;
using System.IO;
namespace system
{
class Rectangle
{
private double length;
private double width;
public void GetDetails()
{
Console.WriteLine("Enter Length: ");
length = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Width: ");
width = Convert.ToDouble(Console.ReadLine());
}
public double GetArea()
{
return length * width;
}
public void Display()
{
Console.WriteLine("Length: {0}", length);
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea()); // this is what i need to be wrote to the file
}
public void WriteToFile()
{
//this is the method where i need to find out the code to get the the getarea to write to the file
}
}
class CalculateRectangle
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
r.GetDetails();
r.Display();
r.WriteToFile(); //this is the main method in which i need the area of the rectangle to be wrote to the file
Console.ReadLine();
}
}
}
Ich kann Ihren Code nicht sehen, um ein Objekt in eine Datei zu schreiben. Und bitte poste [MCVE] –
Hast du überhaupt recherchiert, wie man Text in eine Datei schreibt? Ein gutes Google wird Tausende von Ergebnissen auf, wie dies zu tun ist ... –
Was ist mit nur 'System.IO.File.WriteAllText'? Hast du es versucht? –