using System.Collections.Generic;
static List<string> studentList = new List<string>();
static void Main(string[] args)
Console.WriteLine("Choose an operation:");
Console.WriteLine("1. Add a new student");
Console.WriteLine("2. Remove a student by index");
Console.WriteLine("3. Remove students within a specified range");
Console.WriteLine("4. Clear all students from the list");
Console.WriteLine("5. Display all students");
Console.WriteLine("6. Exit");
int choice = int.Parse(Console.ReadLine());
Console.WriteLine("Exiting the program...");
Console.WriteLine("Invalid choice. Please try again.");
Console.WriteLine("Enter the name of the student:");
string studentName = Console.ReadLine();
studentList.Add(studentName);
Console.WriteLine("Student added successfully!");
static void RemoveStudentByIndex()
Console.WriteLine("Enter the index of the student to remove:");
int index = int.Parse(Console.ReadLine());
if (index >= 0 && index < studentList.Count)
studentList.RemoveAt(index);
Console.WriteLine("Student removed successfully!");
Console.WriteLine("Invalid index. No student removed.");
static void RemoveStudentsInRange()
Console.WriteLine("Enter the starting index of the range:");
int startIndex = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the ending index of the range:");
int endIndex = int.Parse(Console.ReadLine());
if (startIndex >= 0 && startIndex < studentList.Count && endIndex >= startIndex && endIndex < studentList.Count)
studentList.RemoveRange(startIndex, endIndex - startIndex + 1);
Console.WriteLine("Students removed successfully!");
Console.WriteLine("Invalid range. No students removed.");
static void ClearStudents()
Console.WriteLine("All students removed from the list.");
static void DisplayStudents()
if (studentList.Count == 0)
Console.WriteLine("No students in the list.");
Console.WriteLine("List of students:");
for (int i = 0; i < studentList.Count; i++)
Console.WriteLine($"{i}. {studentList[i]}");