将字符串写入文本文件不起作用?
Writing a string to a text file not working?
我正在做一个有趣的小项目,我正在做一个假的车库销售 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();
}
}
}
您没有正确设置要传递的变量。
您正在这样做:
String EventName = Console.ReadLine();
EventName = _Event.Name;
你应该这样做:
String EventName = Console.ReadLine();
_Event.Name = EventName;
然后修复文件中其他同样错误的变量。
我正在做一个有趣的小项目,我正在做一个假的车库销售 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();
}
}
}
您没有正确设置要传递的变量。
您正在这样做:
String EventName = Console.ReadLine();
EventName = _Event.Name;
你应该这样做:
String EventName = Console.ReadLine();
_Event.Name = EventName;
然后修复文件中其他同样错误的变量。