zoukankan      html  css  js  c++  java
  • List<string>中的泛型委托

    我们先看List<T>.Sort()。其定义是:public void Sort( Comparison<T> comparison )

    其要求传入的参数是Comparison<T> comparison。那我们看看Comparison<T> comparison 要求我们传入哪些参数、返回什么样的值。

    查阅MSDN后,我们发现Comparison<T> 要求我们传入两个T的示例,即t1和t2;返回结果是整数,如果t1<t2返回-1,如果相等返回-,如果t1>t2返回

    示例:

    listVideoItems.Sort(delegate(VideoItem v1, VideoItem  v2) { return Comparer<string>.Default.Compare(v1.Title, v2.Title); }); 

    VideoItem video= listVideoItems.Find(delegate(VideoItem v) { return v.Title== "xxxxx"; })

    bool flag= listVideoItems.Exists(delegate(VideoItem v) { return v.Minutes > 25 ;})

    list.Sort(delegate(tt small, tt big) { return small.id - big.id; });    

  • 相关阅读:
    JDK1.5新特性
    mysql的基本使用
    IO简单示例
    序列化
    策略模式
    div+css布局之流体浮动布局
    xp优化
    Junit所使用的设计模式
    SSH使用总结(annotation配置方式)
    hibernate3.6.0使用总结
  • 原文地址:https://www.cnblogs.com/Denny_Yang/p/3799101.html
Copyright © 2011-2022 走看看