You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enumerable.prototype.find = function (compareSelector) {
compareSelector = Utils.createLambda(compareSelector);
var result = null;
this.forEach(function(item) {
if (compareSelector(item)) {
result = item;
return;
}
});
return result;
};
Usage:
var result = Enumerable.from(list).find("x => x.Id == " + somevariable.Id);
It works fine and I hope you like it. It could use some optimization of code quality though.
I don't like the "x => x.Id == " + somevariable.Id part, because the somevariable.Id is outside of the quotation marks. Maybe you got a better solution for this problem.
C# Equivalent would be:
public static T Find<T>(this IList<T> source, Func<T, bool> condition)
{
foreach (var item in source)
{
if (condition(item))
{
return item;
}
}
return default(T);
}
Usage:
var result = list.Find(x => x.Id == somevariable.Id);
The text was updated successfully, but these errors were encountered:
Usage:
It works fine and I hope you like it. It could use some optimization of code quality though.
I don't like the "x => x.Id == " + somevariable.Id part, because the somevariable.Id is outside of the quotation marks. Maybe you got a better solution for this problem.
C# Equivalent would be:
Usage:
The text was updated successfully, but these errors were encountered: