I have a list with multiple variables and would like to add to an array the write to a text file.
class DataFields
{
public string name{get;set;}
public int id{get;set;}
public int age{get;set;}
}
List<DataFields> dfList;
would look something like
Adam 1234 23
Pete 3841 15
Scot 8435 30
DataFields[] result = dfList.ToArray();
File.WriteAllLines(@"C:\File\TextFile.txt", result);
I would like the result to be displayed in the text file similar to the list above but I am having trouble adding the list to the array then display in that order. Any ideas?
File.WriteAllLineswants a collection of strings. You can generate one using LINQ:You should use PascalCase for your property names (Name, Id, Age).