I am new to learning C#, and i'm attempting to create a simple console application that asks the user a set of questions, and then saves the answers into a .txt file on the desktop. However, my below code doesn't seem to work.
static void Main(string[] args)
{
Console.WriteLine("Enter your first name.");
string firstName = Console.ReadLine();
Console.WriteLine("Enter your last name.");
string lastName = Console.ReadLine();
Console.WriteLine("Enter your job title.");
string jobTitle = Console.ReadLine();
Console.WriteLine("What came first, the chicken or the egg?");
string chickenEgg = Console.ReadLine();
string path = @"C:\Users\njones\Desktop\NiallJones.txt";
File.WriteAllText(path, firstName, lastName, jobTitle, chickenEgg);
Console.WriteLine("Your information has been recorded. A copy can be found on your desktop.");
}
I believe the problem lies around the File.WriteAllText part. Please could someone help point me in the right direction as to why this doesn't work, and what I can do in order to improve on this?
Thanks!