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();
        }
    }
}

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

时间: 2024-11-11 19:32:09

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

[LeetCode] Find All Duplicates in an Array 找出数组中所有重复项

Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? Example: Input: [4,3,2,7,

[LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array A = [1,1,1,2,2,3], Your function should return length = 5, and A is now [1,1,2,2,3]. 这道题是之前那道Remove Duplicates from Sorted Array 有序数组中

[LeetCode] 26. Remove Duplicates from Sorted Array ☆(从有序数组中删除重复项)

[LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项 描述 Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this

让NSArray数组中每个对象都调用的方法

1. [array valueForKey:@"title"]; //Returns an array containing the results of invoking valueForKey: using key on each of the array's objects. 使数组中的每个对象都调用valueForKey:方法,并且将每个对象调用方法的结果依次存入一个新的数组中,然后返回 2. [self  setValuesForKeysWithDictionary:dict

声明数组变量/// 计算所有元素的总和/打印所有元素总和/输出/foreach循环/数组作为函数的参数/调用printArray方法打印

实例 下面是这两种语法的代码示例: double[] myList; // 首选的方法 或 double myList[]; // 效果相同,但不是首选方法 创建数组 Java语言使用new操作符来创建数组,语法如下: arrayRefVar = new dataType[arraySize]; 上面的语法语句做了两件事: 一.使用dataType[arraySize]创建了一个数组. 二.把新创建的数组的引用赋值给变量 arrayRefVar. 数组变量的声明,和创建数组可以用一条语句完成,如

【LeetCode】Find Minimum in Rotated Sorted Array 在旋转数组中找最小数

Add Date 2014-10-15 Find Minimum in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in the

LeetCode 442. Find All Duplicates in an Array (在数组中找到所有的重复项)

Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? Example: Input: [4,3,2,7,

Find Minimum in Rotated Sorted Array II 旋转数组中找最小值(有重复元素) @LeetCode

递归 public class Solution { public int findMin(int[] num) { return helper(num, 0, num.length-1); } //with duplicate public static int helper(int[] a, int left, int right){ //one element if(left == right){ return a[left]; } //two elements if(left == ri

[LeetCode]80. Remove Duplicates from Sorted Array II删除数组中的重复值

和第一题不同的地方是,容忍两次重复 虽然题目上说只需要长度,但是否检测的时候如果数组不跟着改变也是不行的 没说清楚题意 自己是用双指针做的,看了大神的答案更简单 public int removeDuplicates(int[] nums) { int i = 0; for (int n : nums) if (i < 2 || n > nums[i-2]) nums[i++] = n; return i; } 原文地址:https://www.cnblogs.com/stAr-1/p/843