Advertisement
StoimenK

C#_Lists_1.5._Remove_Negatives_and_Reverse_V2

Feb 28th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _1._5._Remove_Negatives_and_Reverse_V2
  8. {
  9.     class Program
  10.     {
  11.         static void Main()              // Without lambda function // Lambda functionality is exchnaged with for Loop
  12.         {
  13.             List<int> inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.  
  15.             for (int i = 0; i < inputNum.Count; i++)
  16.             {
  17.                 if (inputNum[i] < 0)
  18.                 {
  19.                     inputNum.RemoveAt(i--);
  20.                 }
  21.             }
  22.  
  23.             if (inputNum.Count == 0)
  24.             {
  25.                 Console.WriteLine("empty");
  26.             }
  27.             inputNum.Reverse();
  28.  
  29.             Console.WriteLine(string.Join(" ", inputNum));
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement