Сортировка и поиск в массиве обьектов - C#
Формулировка задачи:
Добрый день !
помогите решить задачу
Имеется код
Собственно вопрос как передать массив обьектов people в методы Sort();Find() для дальнейших операций над ними
class GuestBook{
public string Lastname { get; set; }
public string Firstname { get; set; }
public string Birthdate { get; set; }
public int Telephone { get; set; }
public GuestBook(string firstname, string lastname, string birthdate, int telephone){
Lastname = lastname;
Firstname = firstname;
Birthdate = birthdate;
Telephone = telephone;
}
public void Sort(){}
public void Find(){}
}class Program{
static void Main(string[] args){
GuestBook[] people = new GuestBook[]{
new GuestBook("jhgygkyhf","hgdhgfjh", "21.11.11", 23123123),
new GuestBook("sgdfgsdfg","qweqweqwe", "21.11.11", 12312312),
new GuestBook("ertwertewrt","xzczxczxc", "21.11.11", 343434),
new GuestBook("sdgadfgsdfg","asdasdasd", "21.11.11", 454545),
new GuestBook("xcvbxcvx","rtyrtyrty", "21.11.11", 56565656),
};
string action = Console.ReadLine(); // действие | поле | запрос
switch (action){
case "show":
p.show();
break;
case "find":
p.find();
break;
case "sort":
p.sort();
break;
}
Console.ReadLine();
}
}Решение задачи: «Сортировка и поиск в массиве обьектов»
textual
Листинг программы
using System;
class GuestBook : IComparable
{
public string Lastname { get; set; }
public string Firstname { get; set; }
public string Birthdate { get; set; }
public int Telephone { get; set; }
public GuestBook(string firstname, string lastname, string birthdate, int telephone)
{
Lastname = lastname;
Firstname = firstname;
Birthdate = birthdate;
Telephone = telephone;
}
public int CompareTo(object obj)
{
if (obj == null)
return 1;
if (obj.GetType() != typeof(GuestBook))
throw new ArgumentException("obj must be 'GuestBook' type", "obj");
return /* реализовать сравнение */
}
}
class Program
{
static void Main(string[] args)
{
GuestBook[] people = new GuestBook[]{
new GuestBook("jhgygkyhf","hgdhgfjh", "21.11.11", 23123123),
new GuestBook("sgdfgsdfg","qweqweqwe", "21.11.11", 12312312),
new GuestBook("ertwertewrt","xzczxczxc", "21.11.11", 343434),
new GuestBook("sdgadfgsdfg","asdasdasd", "21.11.11", 454545),
new GuestBook("xcvbxcvx","rtyrtyrty", "21.11.11", 56565656),
};
string action = Console.ReadLine(); // действие | поле | запрос
switch (action)
{
case "show":
/* */
break;
case "find":
/* */
break;
case "sort":
Array.Sort(people);
break;
}
Console.ReadLine();
}
}