using System;
using System.Collections.Generic;
using System.IO;
public class NoteApp
{
private static List<string> notes = new List<string>();
private const string FILE_NAME = "notes.txt";
ulong s = 20000;
static void Main(string[] args)
{
LoadNotes();
while (true)
{
Console.WriteLine("\nNote Taking App");
Console.WriteLine("1. Add Note");
Console.WriteLine("2. View Notes");
Console.WriteLine("3. Delete Note");
Console.WriteLine("4. Exit");
Console.Write("Choose an option: ");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
AddNote();
SaveNotes(); // Save after adding a note
break;
case "2":
ViewNotes();
break;
case "3":
DeleteNote();
SaveNotes(); // Save after adding a note
break;
case "4":
SaveNotes();
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
return;
default:
Console.WriteLine("Invalid option. Please try again.");
break;
}
}
}
static void AddNote()
{
Console.Write("Enter your note: ");
string note = Console.ReadLine();
notes.Add(note);
Console.WriteLine("Note added successfully.");
}
static void ViewNotes()
{
if (notes.Count == 0)
{
Console.WriteLine("No notes found.");
return;
}
for (int i = 0; i < notes.Count; i++)
{
Console.WriteLine($"{i + 1}. {notes[i]}");
}
}
static void DeleteNote()
{
ViewNotes();
if (notes.Count == 0) return;
Console.Write("Enter the number of the note to delete: ");
if (int.TryParse(Console.ReadLine(), out int index) && index > 0 && index <= notes.Count)
{
notes.RemoveAt(index - 1);
Console.WriteLine("Note deleted successfully.");
}
else
{
Console.WriteLine("Invalid note number.");
}
}
static void LoadNotes()
{
if (File.Exists(FILE_NAME))
{
notes = new List<string>(File.ReadAllLines(FILE_NAME));
}
}
static void SaveNotes()
{
File.WriteAllLines(FILE_NAME, notes);
}
}