Skip to main content
added 278 characters in body
Source Link
svick
  • 10.2k
  • 1
  • 40
  • 54

As far as I know, declaring a helper method as a lambda like this is not commonly done in C#, so I would advise against doing this unless you have a good reason.

Good reasons include:

  • The lambda could do something a separate method can't, like closing over a local variable or using anonymous type.
  • Others in your team agree with you that this is a good practice.

That being said, starting with C# 7.0, C# supports local functions, which are similar to such helper lambdas, but generally better: they have more succinct syntax and are more efficient. So if you used a local function for this purpose, I think that would be perfectly fine.

As far as I know, declaring a helper method as a lambda like this is not commonly done in C#, so I would advise against doing this unless you have a good reason.

Good reasons include:

  • The lambda could do something a separate method can't, like closing over a local variable or using anonymous type.
  • Others in your team agree with you that this is a good practice.

As far as I know, declaring a helper method as a lambda like this is not commonly done in C#, so I would advise against doing this unless you have a good reason.

Good reasons include:

  • The lambda could do something a separate method can't, like closing over a local variable or using anonymous type.
  • Others in your team agree with you that this is a good practice.

That being said, starting with C# 7.0, C# supports local functions, which are similar to such helper lambdas, but generally better: they have more succinct syntax and are more efficient. So if you used a local function for this purpose, I think that would be perfectly fine.

Source Link
svick
  • 10.2k
  • 1
  • 40
  • 54

As far as I know, declaring a helper method as a lambda like this is not commonly done in C#, so I would advise against doing this unless you have a good reason.

Good reasons include:

  • The lambda could do something a separate method can't, like closing over a local variable or using anonymous type.
  • Others in your team agree with you that this is a good practice.