public int Compare(string x,string y)
{
DateTime xDate = DateTime.ParseExact(x, "MMMM", new CultureInfo("en-US"));
DateTime yDate = DateTime.ParseExact(y, "MMMM", new CultureInfo("en-US"));
return (Comparer<DateTime>.Default.Compare(xDate, yDate));
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;

namespace ConsoleApp84
{
class MonthComparer:IComparer<string>
{
public int Compare(string x,string y)
{
DateTime xDate = DateTime.ParseExact(x, "MMMM", new CultureInfo("en-US"));
DateTime yDate = DateTime.ParseExact(y, "MMMM", new CultureInfo("en-US"));
return (Comparer<DateTime>.Default.Compare(xDate, yDate));
}
}
public enum Countries
{
USA,
Italy
}

public class Order
{
public int IdOrder;
public int Quantity;
public bool Shipped;
public string Month;
public int IdProduct;

public override string ToString()
{
return string.Format("IdOrder: {0} -IdProduct:{1}- " + " Quantity:{2}- Shipped:{3} -" + " Month:{4}",
this.IdOrder, this.IdProduct, this.Quantity, this.Shipped, this.Month);
}
}

public class Product
{
public int IdProduct;
public decimal Price;

public override string ToString()
{
return string.Format("IdProduct:{0}-Price:{1}", this.IdProduct, this.Price);
}
}
public class Customer
{
public string Name;
public string City;
public Countries Country;
public Order[] Orders;

public override string ToString()
{
return string.Format("Name:{0}- City:{1}- Country:{2}", this.Name, this, City, this.Country);
}

}
class Program
{
static void Main(string[] args)
{
var customers = new Customer[]
{
new Customer {Name = "Paolo", City = "Brescia",Country = Countries.Italy, Orders = new Order[] {new Order { IdOrder = 1, Quantity = 3, IdProduct = 1 ,
Shipped = false, Month = "January"},new Order { IdOrder = 2, Quantity = 5, IdProduct = 2 ,Shipped = true, Month = "May"}}},
new Customer {Name = "Marco", City = "Torino",Country = Countries.Italy, Orders = new Order[] {new Order { IdOrder = 3, Quantity = 10, IdProduct = 1 ,
Shipped = false, Month = "July"},new Order { IdOrder = 4, Quantity = 20, IdProduct = 3 ,Shipped = true, Month = "December"}}},
new Customer {Name = "James", City = "Dallas",Country = Countries.USA, Orders = new Order[] {new Order { IdOrder = 5, Quantity = 20, IdProduct = 3 ,
Shipped = true, Month = "December"}}},
new Customer {Name = "Frank", City = "Seattle",Country = Countries.USA, Orders = new Order[] {new Order { IdOrder = 6, Quantity = 20, IdProduct = 5 ,
Shipped = false, Month = "July"}}}};

var products = new Product[] {new Product {IdProduct = 1, Price = 10 },new Product {IdProduct = 2, Price = 20 },new Product {IdProduct = 3, Price = 30 },
new Product {IdProduct = 4, Price = 40 },new Product {IdProduct = 5, Price = 50 },new Product {IdProduct = 6, Price = 60 }};

int start = 5, end = 10;

var orders = customers
.SelectMany(x => x.Orders)
.OrderBy(x => x.Month, new MonthComparer());
foreach(var order in orders)
{
Console.WriteLine(order);
}
Console.ReadLine();
}
}
}

DateTimeComparer的更多相关文章

随机推荐

  1. Flask 教程 第二章:模板

    本文翻译自 The Flask Mega-Tutorial Part II: Templates 在Flask Mega-Tutorial系列的第二部分中,我将讨论如何使用模板. 学习完第一章之后,你 ...

  2. swift(四)swift的广义匹配

    //swift的广义匹配 let x = switch x { ...: println("个位数") ...: println("十位数") default: ...

  3. ABP进阶教程4 - 分页排序

    点这里进入ABP进阶教程目录 下载插件 打开Datatables官网(https://datatables.net/download/) 下载插件,复制到JD.CRS.Web.Mvc\wwwroot\ ...

  4. zabbix4.0搭建1

    server端:负责接受到客户端发送过来的数据,并且保存到自己的数据库当中 端口:10051 agent端:负责每隔一定时间进行客户端的数据采集,并且发送给server端 端口:10050 proxy ...

  5. MySQL执行SQL脚本问题 :错误代码2006、1153

    今天用mysql执行了一个60M的SQL脚本遇到了一些错误,经由网上查询如下: 1.#2006 - MySQL server has gone away 出现该错误代码原因如下: 1.应用程序长时间的 ...

  6. Linux—管理用户、用户组及权限

    管理用户 添加用户 [root@localhost ~]# useradd myuser [root@localhost ~]# useradd -m myuser # -d 目录:指定用户主目录,如 ...

  7. [Go] golang实时监控日志文件的包tail

    在linux中有一个tail命令,tail -f可以实时的监控文件新增加的内容,如果用代码实现这个逻辑,可以下载使用这个包go get github.com/hpcloud/tail/... 测试代码 ...

  8. Jmeter之命令行生成HTML报告

    其实每次使用jemter.bat文件启动JMeter时,命令行窗口都会提示我们不要使用GUI窗口进行测试,除非是进行调试脚本 使用命令行生成结果也很测试报告也很简单 jmeter -n -t [jmx ...

  9. 4-9 Panadas与sklearn结合实例

      1.显示百分比的柱状图 In [1]: import pandas as pd import numpy as np import matplotlib.pyplot as plt %matplo ...

  10. CUDA -- 规约求矩阵的行和

    求矩阵每行的和? 可以把每行放入一个不同线程块,这样行与行之间进行粗粒度的并行.而对于每行,其对应的线程块中分配n个线程(对应行宽),使用共享存储器,让每个线程从显存中读取一个数至shared mem ...