Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CODE:
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace RecordStuffAddUpdateLookup
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Student>list=new List<Student>();
- using (StreamReader reader = new StreamReader("..//..//TextFile1.txt"))
- {
- while (true)
- {
- string line = reader.ReadLine();
- if (line == null)
- {
- break;
- }
- string []arr=line.Split(',');
- Student obj=new Student();
- obj.name=arr[0];
- obj.address=arr[1];
- obj.id=Convert.ToDouble(arr[2]);
- obj.phoneNumbers=Convert.ToDouble(arr[3]);
- obj.courses=arr[4];
- list.Add(obj);
- }
- }
- string check="";
- do
- {
- Console.WriteLine("1.Add");
- Console.WriteLine("2.Update");
- Console.WriteLine("3.Lookup");
- Console.WriteLine("4.Exit");
- Console.WriteLine("Choose your number");
- switch (Console.ReadLine())
- {
- case "1":
- Student obj = new Student();
- Console.WriteLine("Enter the name");
- obj.name = Console.ReadLine();
- Console.WriteLine("Enter the address");
- obj.address = Console.ReadLine();
- Console.WriteLine("Enter the id");
- obj.id = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Enter the phoneNumber");
- obj.phoneNumbers = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Enter the courses");
- obj.courses = Console.ReadLine();
- list.Add(obj);
- Console.WriteLine("Added");
- break;
- case "2":
- Console.WriteLine("Enter the name you want to edit");
- string name = Console.ReadLine();
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].name == name)
- {
- Console.WriteLine("Enter the address");
- list[i].address = Console.ReadLine();
- Console.WriteLine("Enter the id");
- list[i].id = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Enter the phoneNumber");
- list[i].phoneNumbers = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Enter the courses");
- list[i].courses = Console.ReadLine();
- }
- }
- break;
- case "3":
- Console.WriteLine("Enter the name you want to search");
- string Name = Console.ReadLine();
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].name == Name)
- {
- Console.WriteLine("Name is " + list[i].name);
- Console.WriteLine("Address is " + list[i].address);
- Console.WriteLine("id is " + list[i].id);
- Console.WriteLine("phone number is " + list[i].phoneNumbers);
- Console.WriteLine("Courses is " + list[i].courses);
- }
- }
- break;
- case "4":
- check = "q";
- break;
- }
- }
- while (check != "q");
- using (StreamWriter writer = new StreamWriter("..//..//TextFile1.txt"))
- {
- for(int i=0;i<list.Count;i++)
- {
- writer.WriteLine(list[i].name + "," + list[i].address + "," + list[i].id + "," + list[i].phoneNumbers + "," + list[i].courses);
- writer.WriteLine(Environment.NewLine);
- }
- }
- }
- }
- class Student
- {
- public string name;
- public string address;
- public double id;
- public double phoneNumbers;
- public string courses;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement