Beispiel #1
0
        public static void PerformTest2()
        {
            /*
             * Anonymous methods provide a technique to pass a code block as a delegate parameter.
             * Anonymous methods are the methods without a name, just the body.
             */

            MyFunc f = delegate(int a)
            {
                return(a * a);
            };
            var result = f(9);

            Console.WriteLine("Result is:{0}", result);

            // direct multicasting
            f += delegate(int b)
            {
                return(b + b);
            };
            var result1 = f(5);

            Console.WriteLine("Result is:{0}", result1);

            MyFunc1 f2 = delegate(int a, int b)
            {
                return(a * b);
            };
            var result2 = f2(9, 45);

            Console.WriteLine("Result is:{0}", result2);
        }
Beispiel #2
0
 /// <summary>
 /// 采用自定义的映射方式,将数据容器中的数据映射到指定的类中
 /// </summary>
 /// <typeparam name="TResult">结果类型</typeparam>
 /// <param name="fun">处理数据的方法</param>
 /// <returns></returns>
 public IEnumerable <TResult> Map <TResult>(MyFunc1 <TResult> fun) where TResult : class, new()
 {
     if (this.Values == null)
     {
         this.Execute();
     }
     if (this.Values != null && this.fieldNames != null)
     {
         if (this.Values.Count == 0)
         {
             yield break;
         }
         else
         {
             foreach (object[] itemValues in this.Values)
             {
                 TResult t = new TResult();
                 this.currValue = itemValues;
                 fun(t);
                 yield return(t);
             }
         }
     }
     else
     {
         throw new Exception("EntityContainer 错误,执行查询没有返回任何行。");
     }
 }
Beispiel #3
0
 public static void Table(MyFunc1 func, double x, double b)
 {
     Console.Write("----- X ----- Y -----");
     while (x <= b)
     {
         Console.WriteLine("| {0,8:0.000} | {1,8:0.000} |", x, func(x));
         x += 1;
     }
     Console.WriteLine("-----------------------");
 }