Predicate委托

1.      定义

表示定义一组条件并确定指定对象是否符合这些条件的方法。

public delegate bool Predicate<T>(

    T obj

);

2.      示例

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace PredicateApp

{

    class Program

    {

        static void Main(string[] args)

        {

 

            MyPredicate<int> myBigger5=

                delegate(int number)

                {

                    if (number > 5)

                    {

                        return true;

                    }

                    return false;

                };

 

            Console.WriteLine("----------MyPredicate------------");

            Console.WriteLine(myBigger5(1));

 

            Console.WriteLine(myBigger5(5));

 

            Console.WriteLine(myBigger5(10));

 

            Predicate<int> big5 = delegate(int number)

            {

                if (number > 5)

                {

                    return true;

                }

                return false;

            };

 

            Console.WriteLine("----------Predicate------------");

            Console.WriteLine(big5(1));

 

            Console.WriteLine(big5(5));

 

            Console.WriteLine(big5(10));

 

            Console.ReadLine();

        }

    }

}

 

 

你可能感兴趣的:(cat)