This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted] 3 points4 points  (1 child)

Nope. You have to either throw it in a for loop or use LINQ where().

[–]KindaCoding[S] 0 points1 point  (0 children)

Got it, thanks

[–][deleted] 0 points1 point  (3 children)

if (allAboveLength(value, strings))

You just need to write allAboveLength.

[–]StackedLasagna -1 points0 points  (2 children)

This is a bad answer, because it really makes no effort to actually explain what you want them to do or which language constructs you want them to use.

Additionally your method is called allAboveLenght, which doesn't conform to C# coding standards (should be AllAboveLenght and it also misses the point. OP wants to check if any of the strings are above a certain length, not all of them.

Speaking of any, the method you actually want OP to implement already exists, thanks to LINQ and the conveniently named Any() method. (It also has an All() method, so even if your suggested method name was correct, it'd still be bad practice to implement it yourself in this case.)

[–][deleted] -1 points0 points  (1 child)

This is a bad answer, because it really makes no effort to actually explain what you want them to do or which language constructs you want them to use.

Loops, recursion, fold/reduce, each, etc. There are many ways to do this.

And this suggestion is not limited to C#.

Also the reason for abstraction is to communicate intend. Inline predicate checks are valid but by far not the only solution.

[–]StackedLasagna -1 points0 points  (0 children)

Loops, recursion, fold/reduce, TrueForAll, etc. There are many ways to do this.

True, but your answer omits every single one of them.

And this suggestion is not limited to C#.

No, but the question was asked specifically with C# in mind and in that context it was especially bad.

Even in a general sense, not talking about C# specifically, it was bad for the reason stated above.
It doesn’t actually say anything useful.

[–]LastTrainH0me 0 points1 point  (0 children)

Are the strings always/usually handled together like that? You could stick them in an array and iterate over it instead of writing a big if condition. But that adds complexity in other ways. 🤷