How to remove the last N elements from an array using Linq in C#

1 Answer

0 votes
using System;
using System.Linq;
 
class Program
{
    static void Main() {
        string[] array = { "c#", "java", "c", "python", "php", "c++", "go", "rust" };
        
        int N = 3;
        var result = array.SkipLast(N);
        
        Console.WriteLine(string.Join(", ", result));
    }
}
   
   
   
/*
run:
      
c#, java, c, python, php
    
*/

 



answered Jul 5, 2023 by avibootz
...