Write a program in C# to remove a range of items from a list by passing the start index and number of elements to remove in LINQ Query


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class LinqExercise21
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. List<string> list = new List<string>();
  12. list.Add("a");
  13. list.Add("b");
  14. list.Add("c");
  15. list.Add("d");
  16. list.Add("e");
  17. list.Add("f");
  18.  
  19.  
  20. var result = from y in list
  21. select y;
  22. Console.Write("Here is the list of items : \n");
  23. foreach (var tchar in result)
  24. {
  25. Console.WriteLine("Char: {0} ", tchar);
  26. }
  27.  
  28. list.RemoveRange(1, 4);
  29.  
  30. var _result = from n in list
  31. select n;
  32. Console.Write("\nHere is the list after removing the four items starting from the list : \n");
  33. foreach (var removeChar in _result)
  34. {
  35. Console.WriteLine("Char: {0} ", removeChar);
  36. }
  37.  
  38. Console.ReadLine();
  39. }
  40. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts