1

These two lines in C# seem to do the same thing:

int idIndex = row.attributeNames.FindIndex(i => i.ToString() == "searchTerm");
int idIndex = row.attributeNames.FindIndex((object i) => { return i.ToString() == "searchTerm"; });

Are these two lines executed differently at all?

It seems not, but I remember seeing somewhere that there are different ways of writing lambdas in C# that are executed slightly differently.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Zach Smith
  • 8,458
  • 13
  • 59
  • 133
  • If in first case `i` is `object` then there're the same. First one is a shorthand of the second. Both are `Func` or it's the same as `Predicate`. And both are delegates with signature `bool(object i)`. – pkuderov Jul 07 '17 at 23:27
  • See also https://stackoverflow.com/questions/17240642/difference-between-lambda-expression-and-expression-lambda (not quite the same question, but still relevant) – Peter Duniho Jul 07 '17 at 23:37

0 Answers0