using System.Collections.Generic;
using System.Threading.Tasks;
public static void Main()
var path = "fd1/fd2/file.txt";
var splits = path.Split('/');
var res = splits.Slice(0, 2);
var str = res.Aggregate("", (cur, it) => $"{cur} {it}");
Console.WriteLine($"res: {str}");
Console.WriteLine($"slice {splits.Last()}");
public static class Extensions
public static string Slice(this string source, int start, int end)
end = source.Length + end;
return source.Substring(start, len);
public static IEnumerable<T> Slice<T>(this T[] source, int start, int end)
end = source.Length + end;
for (int i = start; i <= end; i++)