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. 为什么要做外链建设?seo优化与发布外链速度有哪些联系?

    对于SEO员工来说,我们每天都在处理网页.从内容创建的角度来看,我们每天创建大量的URL并进入索引状态.与网站的受欢迎程度相比,网站每天也会生成大量的外部链接. 实际上,相对于链接而言,它满足了搜索引 ...

  2. Django---SETTINGS配置(***)

    Django---SETTINGS核心配置项 django核心配置项 Django的默认配置文件中,包含上百条配置项目,其中很多是我们'一辈子'都不碰到或者不需要单独配置的,这些项目在需要的时候再去查 ...

  3. WeTest全球化服务,为使命召唤手游质量保驾护航

    导读 使命召唤系列作为经典FPS游戏,以良好的表现与出色的射击手感,颠覆了玩家对传统第一人称射击的传统观念.同名手游(CODM)10月份在海外上线,仅一周内下载量就已突破一亿次,更是横扫139个国家及 ...

  4. Word模板注入攻击

    Word模板注入攻击 0x00 工具准备 phishery:https://github.com/ryhanson/phishery/releases office版本:office 2010 0x0 ...

  5. java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys.

    创建Spring Cloud Sleuth对应Zipkin服务,引入依赖: <dependency> <groupId>io.zipkin.java</groupId&g ...

  6. Debian创建.desktop文件(Create .desktop file in Debian/Gnome)

    在Debian系Linux中,用于标识应用的启动文件.desktop file是位于/usr/share/applications目录下的,Gnome会将这些文件在菜单中展示为启动图标,也可以固定在d ...

  7. CodeForces - 1228D (暴力+思维+乱搞)

    题意 https://vjudge.net/problem/CodeForces-1228D 有一个n个顶点m条边的无向图,在一对顶点中最多有一条边. 设v1,v2是两个不相交的非空子集,当满足以下条 ...

  8. HTML 中img标签不显示

    异常 图片请求响应吗: 403, url响应如下: Request Method: GET Status Code: 403 Forbidden Remote Address: ***.***.**. ...

  9. Xshell使用教程

    Xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议.Xshell 通过互联网到远程主机的安全连接以及它创新性的设 ...

  10. c# 第33节 类的封装--访问修饰符

    本节内容: 1:封装的简介 2:封装怎么实现 3:访问修饰符 1:封装的简介 2:封装怎么实现 3:访问修饰符 4:访问修饰符注意点