好吧,所以我有一个c#简单程序,您可以输入您的姓名,姓氏和年龄,所以我试图找到一种方法,在程序运行时可以从程序中删除特定数据。例如,我输入一个名称和一个姓氏,然后获得一个删除该名称或姓氏的选项。
下面列出了代码!
using System;
namespace calc
{
public class Student
{
public string firstName;
public string lastName;
public int age;
}
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Choose from one of the following");
Console.WriteLine(" 1. Add Student ");
Console.WriteLine(" 2. Remove Student ");
int number = int.Parse(Console.ReadLine());
string[] names = new string[4];
if (number == 1)
{
// code for adding student name and storing it in an array
Console.WriteLine("Write Student first name");
Student first1 = new Student();
string first = Console.ReadLine();
first1.firstName = first;
// takes in students last name
Console.WriteLine(" Write Student Last Name");
Student last1 = new Student();
string last = Console.ReadLine();
last1.lastName = last;
// takes age
Console.WriteLine(" Write age");
Student age1 = new Student();
int age = int.Parse(Console.ReadLine());
age1.age = age;
Console.WriteLine(first1.firstName);
Console.WriteLine(last1.lastName);
Console.WriteLine(age1.age);
}
else if (number == 2)
{
Console.WriteLine(" 1. Remove First Name ");
Console.WriteLine(" 2. Remove Last Name ");
int number2 = int.Parse(Console.ReadLine());
if (number2 == 1)
{
}
}
}
}
}