using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
List<int> list= new List<int>();
for (int i = 1; i < 101; i++)
{
list.Add(i);
}
List<int> result= list.Where(x => x % 2 == 0).ToList();
foreach (var ret in result)
{
Console.WriteLine(ret);
}
Console.ReadKey();
}
}
}
用LinQ、Lambda判断奇数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
List<int> list= new List<int>();
for (int i = 1; i < 101; i++)
{
list.Add(i);
}
List<int> result= list.Where(x => x % 2 != 0).ToList();
foreach (var ret in result)
{
Console.WriteLine(ret);
}
Console.ReadKey();
}
}
}