C#中的LINQ凡(表达).FirstorDefault()VS .FirstOrDefault(表达) [英] C# Linq Where(expression).FirstorDefault() vs .FirstOrDefault(expression)

查看:467
本文介绍了C#中的LINQ凡(表达).FirstorDefault()VS .FirstOrDefault(表达)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的LINQ和在使用什么性能此事困境

  VAR的结果= ResultLists() 。凡(C => c.code ==ABC)FirstOrDefault()。 

VAR的结果= ResultLists()FirstOrDefault(C => c.code ==ABC);


解决方案

无论是罚款。



他们都懒洋洋地运行 - 如果源列表中有一万件,但随后的第十项匹配都将只迭代从源头上10个项目



性能应该是几乎相同的任何差别是完全微不足道。


I'm very new in Linq and in dilemma of what to use for performance matter

var result = ResultLists().Where( c=> c.code == "abc").FirstOrDefault();
vs
var result = ResultLists().FirstOrDefault( c => c.code == "abc");

解决方案

Either is fine.

They both run lazily - if the source list has a million items, but the tenth item matches then both will only iterate 10 items from the source.

Performance should be almost identical and any difference would be totally insignificant.

这篇关于C#中的LINQ凡(表达).FirstorDefault()VS .FirstOrDefault(表达)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆