Clean way to return array indices matching a condition using LINQ?

Personally, I'd go with this: myarray . Select((p, i) => new { Item = p, Index = I }) . Where(p => SomeCondition(p.

Item)) . Select(p => p. Index).

I would probably write an extension method, but if I chose not to, I would do this: array . Select((item, index) => SomeCondition(item)? Index : -1) .

Where(index => index! = -1); It's exactly what you are doing already, but less verbose since it uses the ternary if operator instead of the if/else block.

I wonder if there is better way to initialize an array of reference type object, like this. I tried Enumerable. I also tried Array.

Any other idea?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions