Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq 更新/修剪Lambda where表达式中的值_Linq_C# 4.0_Lambda_Where - Fatal编程技术网

Linq 更新/修剪Lambda where表达式中的值

Linq 更新/修剪Lambda where表达式中的值,linq,c#-4.0,lambda,where,Linq,C# 4.0,Lambda,Where,我有一个Lambda where表达式,它根据传入的ID过滤客户列表。这很好,但是我想在返回记录时从CreationDate字段中删除时间戳。在Lambda表达式中是否有这样做的方法 这是我的Lambda表达式,它返回我的客户记录: customers = customers.Where(c => c.Business_Type == businessType); 但是,我想做如下工作: customers = customers.Where(c => c.Business_Typ

我有一个Lambda where表达式,它根据传入的ID过滤客户列表。这很好,但是我想在返回记录时从CreationDate字段中删除时间戳。在Lambda表达式中是否有这样做的方法

这是我的Lambda表达式,它返回我的客户记录:

customers = customers.Where(c => c.Business_Type == businessType);
但是,我想做如下工作:

customers = customers.Where(c => c.Business_Type == businessType, c.CreationDate=c.CreationDate.Value.ToShortDateString());

LINQ并不意味着执行序列元素的突变。只需获取
Where
的返回值,并使用
foreach
执行变异,这是处理此问题的惯用方法:

var customers = customers.Where(c => c.Business_Type == businessType).ToArray();
foreach(var c in customers)
{
    c.CreationDate = c.CreationDate.Value.ToShortDateString();
}

LINQ并不意味着执行序列元素的突变。只需获取
Where
的返回值,并使用
foreach
执行变异,这是处理此问题的惯用方法:

var customers = customers.Where(c => c.Business_Type == businessType).ToArray();
foreach(var c in customers)
{
    c.CreationDate = c.CreationDate.Value.ToShortDateString();
}

回答你的问题,是的,你可以。在如下方法中打开表达式:customers=customers.Where(c=>{bool r=c.Business_Type==businessType;c.CreationDate=c.CreationDate.Value.ToShortDateString();return r});不是建议你回答你的问题,是的,你可以。在如下方法中打开表达式:customers=customers.Where(c=>{bool r=c.Business_Type==businessType;c.CreationDate=c.CreationDate.Value.ToShortDateString();return r});并不是说它是被推荐的。。。