fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. struct MyStruct
  7. {
  8. public int index;
  9. }
  10. private static MyStruct?[] GetRow(int?[] row)
  11. {
  12. return row.Select(
  13. (el, ind) => el == 0 ? (MyStruct?)new MyStruct { index = ind } : null)
  14. .Where(el => el != null).ToArray();
  15. }
  16. static void Main(string[] args)
  17. {
  18. int?[] row = new int?[] { 0, null, 1, 2, 3, 0 };
  19. var ar = GetRow(row);
  20.  
  21. ar.Select(el => { Console.WriteLine(el?.index); return el; }).ToArray();
  22. Console.WriteLine(ar.Count());
  23. }
  24. }
Success #stdin #stdout 0.01s 29800KB
stdin
Standard input is empty
stdout
0
5
2