using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _15linq查询的模拟
{
public delegate bool CheckDelegate(int num);
class Program
{
static void Main(string[] args)
{
int[] nums = { 11, 12, 31, 10, 59, 13, 56, 45, -1, 49 };
//foreach (int item in nums.Where(e => e % 2 == 0))
//{
// Console.WriteLine(item);
//}
//int[] n = MyWhere(nums, e => e % 2 == 0);
List<int> list = new List<int>();
for (int i = 100; i < 1000; i++)
{
list.Add(i);
}
int[] ns = MyWhere(list.ToArray(),e=>
{
// 123
int n1 = e % 10; // 3
int n2 = e / 10 % 10; // 2
int n3 = e / 100; // 1
return (n1 * n1 * n1 + n2 * n2 * n2 + n3 * n3 * n3) == e;
});
Console.WriteLine("开始打印:");
foreach (int item in ns)
{
Console.WriteLine(item);
}
Console.WriteLine("打印结束!");
Console.ReadKey();
}
public static int[] MyWhere(int[] nums, CheckDelegate ck)
{
List<int> list = new List<int>();
for (int i = 0; i < nums.Length; i++)
{
if (ck(nums[i]))
{
list.Add(nums[i]);
}
}
return list.ToArray();
}
}
}