Fadugba Jeremiah

Fadugba Jeremiah

  • NA
  • 49
  • 18.2k

Saving Console variables to a file

Aug 23 2015 6:17 AM
Hello i want to retrieve user inputed variable from this method: they are all string and has been declared globally.
public void DetailsMovie()
{
Console.WriteLine("\n \v Enter the movie title");
MovieTitle = Console.ReadLine();
Console.WriteLine("\n Enter the year it was released");
MovieYear = Console.ReadLine();
Console.WriteLine("\n Enter the name of the movie's publisher");
MoviePublisher = Console.ReadLine();
Console.WriteLine("\n What is the length of the movie (in hours)");
MovieLength = Console.ReadLine();
}
 
and to be used in this place
 
 
 public void SaveData()
{
Console.Write("Enter filename");
string Filename = Console.ReadLine();
if (File.Exists(Filename))
{
StreamWriter file = new StreamWriter(Filename, true);
file.WriteLine("", MovieTitle);
file.WriteLine("",MovieYear);
file.WriteLine("",MoviePublisher);
file.WriteLine("",MovieLength);
}
else
{
StreamWriter file = new StreamWriter(Filename + ".txt");
file.Write(String.Format("",MovieTitle));
file.Write(String.Format("",MovieYear));
file.Write(String.Format("",MoviePublisher));
file.Write(String.Format("",MovieLength));
file.Close();
Console.Write(" saved successful");
}
}
 
 please how do i go about? The whole point is to save it into a text file
 

Answers (1)