我正在制作一个有趣的小项目,其中我在制作假的Garage Sale POS系统。它现在很小,以后再增加。现在,我有系统询问您车库销售(活动)的名称及其发生的日期。然后将其保存到文本文件。但是,它仅保存单词,而不保存变量 我做错什么了吗?预先感谢!
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GarageSale.Domain;
using System.IO;
namespace GarageSaleConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to the AppTech GarageSale System! What is the name of your event?");
Event _Event = new Event();
String EventName = Console.ReadLine();
EventName = _Event.Name;
Console.WriteLine("Your event is called" + EventName + "Got it");
Console.WriteLine(" ");
Console.WriteLine("Please enter the date your event starts in this format MM/DD/YYYY");
String DateStart = Console.ReadLine();
DateStart = _Event.Date1;
Console.WriteLine(" ");
Console.WriteLine("Please enter the date your event ends in this format MM/DD/YYYY");
String DateEnd = Console.ReadLine();
DateEnd = _Event.Date2;
Console.WriteLine(" ");
Console.WriteLine("Your event Starts " + DateStart + "and ends " + DateEnd + "Got it");
String[] EventInformation = { "Event Name:" + _Event.Name, "Event Dates", _Event.Date1 + " To " + _Event.Date2, };
System.IO.File.WriteAllLines("C:\\Users\\Jackson\\Desktop\\EventInfoAssignment1LHeller/EventInformation.txt", EventInformation);
Console.ReadLine();
}
}
}
答案 0 :(得分:2)
您没有正确设置要传入的变量。
您正在这样做:
String EventName = Console.ReadLine();
EventName = _Event.Name;
您应该这样做:
String EventName = Console.ReadLine();
_Event.Name = EventName;
然后修复文件中同样错误的其余变量。