实际上在电话簿中从其功能添加成员我做了但它必须排序,因为我不知道如何做它可以任何人帮助我,谢谢,这里是代码
记录存储为struct(订阅者)并存储在List(订阅者)
中namespace phonebook
{
class Program
{
static List<Subscriber> subscribers = new List<Subscriber>();
public void Add()
{
Subscriber subscriber = new Subscriber();
Console.WriteLine("Enter the firstname");
subscriber.firstname = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Enter the lastname");
subscriber.lastname = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Enter the streetname");
subscriber.streertname = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Enter the city");
subscriber.city = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Enter the country");
subscriber.country = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Enter the buildingnumber");
subscriber.buildingnumber = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Enter the phonenumber");
subscriber.phonenumber = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Enter the email");
subscriber.email = Console.ReadLine();
subscribers.Add(subscriber);
Console.ReadKey();
}
public struct Subscriber
{
public string firstname;
public string lastname;
public string streertname;
public string city;
public string country;
public string buildingnumber;
public string phonenumber;
public string email;
}
}
答案 0 :(得分:1)
如果你想根据fristname对它进行排序,你可以试试这个:
subscribers.Sort ((sub1,sub2)=>sub1.firstname.CompareTo(sub2.firstname));