c# - Linq ForEach vs All Performance review -
For most of the time I'm using All (and Returns Right) instead of ForEach to use all the time For everybody (in the case of IEnumerable), it is a good practice to use all, I understand that everyone can be run on IEnumerable, while foreign only runs on the list
var Wells = GlobalDataModelWellList.Where (U = & gt; U. Reef projectname == project.OldProjectName); If (well.no) (well) All. (U => {u.RefProjectName = project.ProjectName; back true;}); } Var wellsList = GlobalDataModel.WellList.Where (U = & gt; u.RefProjectName == project.OldProjectName) .toList (); Well list Foreic (U => U. Reef project name = project.product name);
No, you are misusing the all
method . Take a look at
It determines that all elements of the sequence satisfy a condition.
Should be used to determine that all elements are true / false, in some situations, this is not to produce side effects .
list. Foreike
is for use for side effects if you already have the list & lt; T & gt;
is upfront, you can use it. For calling toList
and list
, just for the list. ForEach
is not worth it connects to another O (N) operation.
Do not use all
for side effects, when List.ForEach
is not acceptable to you. List already recommended way of using your choice Loop, nothing can be better than anything else.
There is something about saying something in Erichspot, note that it has been removed in the modern UI application, it can also be removed in the desktop version of .net.
Comments
Post a Comment