Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace TextFileIO
- {
- class Program
- {
- static void Main(string[] args)
- {
- string folder = @"C:\Parentfolder\Childfolder3\";
- string filename = "Datafile.txt";
- string fullPath = folder + filename;
- Console.WriteLine("Write File\n");
- List<string> addData = new List<string>();
- addData.Add("Lloyd Samuel,Garcia,Cebu City,lloydgarcia123@gail.com,09224542311");
- File.WriteAllLines(fullPath, addData);
- Console.WriteLine("All entries written\n");
- //Display
- Console.WriteLine("Read File\n");
- List<string> list = File.ReadAllLines(fullPath).ToList();
- List<PersonInfo> people = new List<PersonInfo>();
- foreach (var line in list)
- {
- string[] entries = line.Split(',');
- PersonInfo newPerson = new PersonInfo();
- newPerson.FirstName = entries[0];
- newPerson.LastName = entries[1];
- newPerson.Address = entries[2];
- newPerson.Email = entries[3];
- newPerson.Contact = entries[4];
- people.Add(newPerson);
- }
- foreach (var person in people)
- {
- Console.WriteLine($"{ person.FirstName}, { person.LastName}, { person.Address}, { person.Email}, { person.Contact}");
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement