I’m curious how to write this, if it’s possible, as a lambda expression.
For (int i = 0; i < MyList.Count; i++)
{
MyMethod(MyList[i].Id, MyList[i].Value);
}
public void MyMethod(string id, string value)
{
// do kung-fu
}
I’ve seen how I can use lambda expressions to call an object’s methods, but I can’t find one to do it this way.
I realize a loop works just fine. I’m just wondering if it could be done and how.
I wouldn’t use a lambda expression – but I would use a
foreachloop:If you really want to use
List<T>.ForEachyou could write:… but I wouldn’t.