Как верно реализовать метод CompareTo для сортировки массива объектов по определенному полю объектов. Вот то, что у меня дано и набросал:
class Program
{
static void Main(string[] args)
{
Console.ReadKey();
}
}
public abstract class Software
{
public string name_soft;
public string made;
public virtual void Information()
{
Console.WriteLine(this.name_soft+" "+this.made);
}
public virtual bool can=> true;
}
public class FreeSoftware : Software
{
public FreeSoftware(string name, string made)
{
base.name_soft = name;
base.made = made;
}
}
public class SharewareSoftware : Software
{
private DateTime date_instal;
private DateTime period_free;
public SharewareSoftware(string name, string made, DateTime date_instal, DateTime period)
{
base.name_soft = name;
base.made = made;
this.date_instal = date_instal;
period_free = period;
}
public override void Information()
{
Console.WriteLine(name_soft+" "+made+" "+date_instal.ToString("d")+" "+period_free.ToString("d"));
}
public override bool can=> (new DateTime(date_instal.Year - period_free.Year, date_instal.Month - period_free.Month, date_instal.Day - period_free.Day))<= DateTime.Now;
}
public class ProprietarySoftware : Software {
private DateTime date_instal;
private DateTime time_use;
private double price;
public ProprietarySoftware(string name,string made,DateTime date_instal,DateTime time_use,double price)
{
name_soft = name;
base.made = made;
this.date_instal = date_instal;
this.time_use = time_use;
this.price = price;
}
public override void Information()
{
Console.WriteLine(name_soft+" "+made+" "+ price+" "+date_instal.ToString("d")+" "+time_use.ToString("d"));
}
public override bool can=> (new DateTime(date_instal.Year - time_use.Year, date_instal.Month - time_use.Month, date_instal.Day - time_use.Day)) == DateTime.Now;
}
Я не понимаю как мне создать массив из различных объектов и по поводу реализации метода сортировки... Может я очень тупой, но я просто не понимаю.