欢迎加我的QQ群:193522571,一起来讨论、交流!

LinQ 泛型方法Array>ForEach在数组中进行迭代并调用自定义的委托

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace LambdaExpressionAction
{
    class Program
    {
        static void Main(string[] args)
        {
            //定义输出委托
            Action<double> print = amount => Console.WriteLine("{0:c}", amount);
            //定义新委托并引用上面的输出委托
            Action<double> michiganSalesTax = amount => print(amount *= 1.06);
            //定义一个数组
            var amounts = new double[] { 10.36, 12.00, 134 };
            //泛型方法Array>ForEach在amounts中进行迭代并调用michiganSalesTax
            Array.ForEach<double>(amounts, michiganSalesTax);
            Console.ReadLine();
        }
    }
}

 

posted @ 2014-07-13 09:25  swtool  阅读(374)  评论(0编辑  收藏  举报
欢迎加我的QQ群:193522571,一起来讨论、交流!