- Edited
Ok so I am tired of having to write a foreach loop everytime I want to do something to the members of the collection. I wrote the following extension method and tried to use it but I got an error:
So what's going on?
public static void ForEach<T>(this IEnumerable<T > list, Action<T> action)
where T : class
{
foreach (T item in list)
action(item);
}
//this is how I'm using it:
IList<Category> nodes = _repository.GetNodes()
.GetRightNodes(node).ToList()
.ForEach(c => (c.Left = c.Left + 2) && (c.Right = c.Right + 2));
But I'm getting this error:
Also, using the ForEach extension method that is already available on IList causes the same error.Operator && cannot be applied to operands of type 'int' and 'int'
So what's going on?