易丰科技

标题: Predicate type in the C# [打印本页]

作者: Calvin    时间: 2011-10-16 14:20
标题: Predicate type in the C#

  1. using System;

  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         //
  7.         // This Predicate instance returns true if the argument is one.
  8.         //
  9.         Predicate<int> isOne =
  10.             x => x == 1;
  11.         //
  12.         // This Predicate returns true if the argument is greater than 4.
  13.         //
  14.         Predicate<int> isGreaterEqualFive =
  15.             (int x) => x >= 5;

  16.         //
  17.         // Test the Predicate instances with various parameters.
  18.         //
  19.         Console.WriteLine(isOne.Invoke(1));
  20.         Console.WriteLine(isOne.Invoke(2));
  21.         Console.WriteLine(isGreaterEqualFive.Invoke(3));
  22.         Console.WriteLine(isGreaterEqualFive.Invoke(10));
  23.     }
  24. }
复制代码







欢迎光临 易丰科技 (http://forum.yftek.com/) Powered by Discuz! X3