You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
970 B
C#

6 years ago
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Linq.Expressions;
using Xunit;
namespace LinqStudy.Test.LinqToObject
{
/// <summary>
/// where操作符过滤查询条件
/// </summary>
public class WhereTest
{
[Fact]
public void Where_Test()
{
var Persons = new List<Person>()
{
new Person(){ Id=1,Name="zhangsan",Age=2},
new Person(){ Id =2,Name="lishi",Age=33}
};
var query = Persons.Where(p => p.Name.StartsWith("zhang"));
var age = query.FirstOrDefault()?.Age;
Assert.Equal(2, age);
}
[Fact]
public void Where_Argm_Test()
{
List<Person> Persons = null;
Action act = ()=> { Persons.Where(p => p.Name.StartsWith("zhang")); };
Assert.Throws<ArgumentNullException>(act);
}
}
}