user8715790
user8715790

Reputation:

Writing a string to a text file not working?

Im making a fun little project where i'm making a fake Garage sale POS system. its small right now and ill be adding more later. Right now i have the system ask you for the name of the Garage sale (event) and the dates on which they occur. Then it saves it to a text file. However it only saves the Words and not the variables is there something i'm doing wrong? thanks in advance!

Code:

  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();
    }
}
}

Upvotes: 0

Views: 69

Answers (1)

eVolve
eVolve

Reputation: 1456

You are not setting the variables you are passing in correctly.

You are doing this:

String EventName = Console.ReadLine();

    EventName = _Event.Name;

You should be doing it like this:

String EventName = Console.ReadLine();

    _Event.Name = EventName;

Then fix the rest of the variables that are also wrong in the file.

Upvotes: 2

Related Questions