委托和匿名方法学习小结~
最近几日在弄这方面的东西,觉得很多地方(书上,网上)将的都不是很彻底,于是自己琢磨了一下,以下是我的成果,
废话不说,上代码:
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace linq
{
class Program
{
static int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 2 };
static void Main(string[] args)
{
a.display(p => p == 2);
Console.ReadLine();
}
}
public static class MYE
{
public static void display(this int[] source, Func<int, bool> func)
{
List<int> val = new List<int>();
foreach (int i in source)
if (func(i))
val.Add(i);
foreach (var i in val)
Console.WriteLine(i);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace linq
{
class Program
{
static int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 2 };
static void Main(string[] args)
{
a.display(p => p == 2);
Console.ReadLine();
}
}
public static class MYE
{
public static void display(this int[] source, Func<int, bool> func)
{
List<int> val = new List<int>();
foreach (int i in source)
if (func(i))
val.Add(i);
foreach (var i in val)
Console.WriteLine(i);
}
}
}
大家提点建议及方向~