using System;
using System.Linq;
using System.Collections.Generic;
public static class ListExtensions
{
/// <summary>
/// Finds the indices of all objects matching the given predicate.
/// </summary>
/// <typeparam name="T">The type of objects in the list.</typeparam>
/// <param name="list">The list.</param>
/// <param name="predicate">The predicate.</param>
/// <returns>Indices of all objects matching the given predicate.</returns>
public static IEnumerable<int> FindIndices<T>(this IList<T> list, Func<T, bool> predicate)
{
return list.Where(predicate).Select(list.IndexOf);
}
}
public static class Test
{
public static void Main()
{
var list = new List<int> { 10, 11, 23, 34, 56, 43 };
var indices = list.FindIndices(value => value > 23);
foreach(var index in indices)
{
Console.WriteLine(index);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWM7CgpwdWJsaWMgc3RhdGljIGNsYXNzIExpc3RFeHRlbnNpb25zCnsKICAgIC8vLyA8c3VtbWFyeT4KICAgIC8vLyBGaW5kcyB0aGUgaW5kaWNlcyBvZiBhbGwgb2JqZWN0cyBtYXRjaGluZyB0aGUgZ2l2ZW4gcHJlZGljYXRlLgogICAgLy8vIDwvc3VtbWFyeT4KICAgIC8vLyA8dHlwZXBhcmFtIG5hbWU9IlQiPlRoZSB0eXBlIG9mIG9iamVjdHMgaW4gdGhlIGxpc3QuPC90eXBlcGFyYW0+CiAgICAvLy8gPHBhcmFtIG5hbWU9Imxpc3QiPlRoZSBsaXN0LjwvcGFyYW0+CiAgICAvLy8gPHBhcmFtIG5hbWU9InByZWRpY2F0ZSI+VGhlIHByZWRpY2F0ZS48L3BhcmFtPgogICAgLy8vIDxyZXR1cm5zPkluZGljZXMgb2YgYWxsIG9iamVjdHMgbWF0Y2hpbmcgdGhlIGdpdmVuIHByZWRpY2F0ZS48L3JldHVybnM+CiAgICBwdWJsaWMgc3RhdGljIElFbnVtZXJhYmxlPGludD4gRmluZEluZGljZXM8VD4odGhpcyBJTGlzdDxUPiBsaXN0LCBGdW5jPFQsIGJvb2w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